Outputting Results (Of Bean Writing)
Betwixt is flexible when it comes to outputting the results of bean writing.
The abstract Pushing Results to a Textual Stream
Rendering Empty Tags
Empty tags (ones containing no body content and no child nodes) can be rendered
in two ways: as a single closed tag (for example BeanWriter writer = new BeanWriter(out); writer.setEndTagForEmptyElement(true); Content EncodingWhen writing character data (the content between markup tags) to a textual stream, sections of character data can be processed in various ways by Betwixt with the aim of easily producing valid xml from beans. In particular, Betwixt assumes that bean's property values are plain java rather than pre-processed xml and so may contain characters that should be escaped. There are two primary use cases for this processing:
Betwixt provides a plug-in
MixedCharacterEncodingStrategy
and a property on
BeanWriter
which allows the processing to be varied.
Factory constants are provided on
For example, to have all content wrapped in BeanWriter writer = ... writer.setMixedContentEncodingStrategy(MixedContentEncodingStrategy.CDATA);
By default, Betwixt uses character escaping only. However, the default
strategy also supports per-property specification through
setting the appropriate option.
Setting the <?xml version='1.0'?> <info primitiveTypes="attribute"> <element name='some-bean'> ... <element name='some-property' property='someProperty'> <option> <name>org.apache.commons.betwixt.mixed-content-encoding</name> <value>CDATA</value> </option> </element> ... </element> </info> Pushing Results to SAX
|