Tutorial
This is a simple step-by-step The Object Model
So, the place we'll start is with an object model for RSS 0.91. This was originally created for Digester by Craig R. McClanahan and Ted Husted with a few amendments for this tutorial. There are only four main objects in the model: The application simply processes an xml file in RSS format and creates a plain text version. This isn't really very useful but is a good demonstration of bean reading. The XMLRSS 0.91 is an XML vocabulary for describing metadata about websites commonly used to supply news channels. RSS 0.91 is a little elderly and has quite a simple - but elegant - DTD: <!ELEMENT rss (channel)> <!ATTLIST rss version CDATA #REQUIRED> <!-- must be "0.91"> --> <!ELEMENT channel ( title | description | link | language | item+ | rating? | image? | textinput? | copyright? | pubDate? | lastBuildDate? | docs? | managingEditor? | webMaster? | skipHours? | skipDays?)*> <!ELEMENT title (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT link (#PCDATA)> <!ELEMENT image (title | url | link | width? | height? | description?)*> <!ELEMENT url (#PCDATA)> <!ELEMENT item (title | link | description)*> <!ELEMENT textinput (title | description | name | link)*> <!ELEMENT name (#PCDATA)> <!ELEMENT rating (#PCDATA)> <!ELEMENT language (#PCDATA)> <!ELEMENT width (#PCDATA)> <!ELEMENT height (#PCDATA)> <!ELEMENT copyright (#PCDATA)> <!ELEMENT pubDate (#PCDATA)> <!ELEMENT lastBuildDate (#PCDATA)> <!ELEMENT docs (#PCDATA)> <!ELEMENT managingEditor (#PCDATA)> <!ELEMENT webMaster (#PCDATA)> <!ELEMENT hour (#PCDATA)> <!ELEMENT day (#PCDATA)> <!ELEMENT skipHours (hour+)> <!ELEMENT skipDays (day+)>
Since Mapping Channel and Image
Every xml document has a root node.
Every
Channel is the root object mapping to the <?xml version="1.0" encoding="UTF-8" ?> <info primitiveTypes="element"> <element name="rss"> <attribute name="version" property="version"/> <element name="channel"> <element name="title" property="title"/> <element name="item" property="items"/> <element name="textinput" property="textInput"/> <element name="skipDays"> <element name="day" property="skipDays"/> </element> <element name="skipHours"> <element name="hour" property="skipHours"/> </element> <addDefaults/> </element> </element> </info>
This describes how elements and attributes in the xml are mapped to properties
in a Channel object.
There are a number of collective properties: those that are mapped to a many
objects (rather than just one). For example, the
items
property is backed by an
Notice the See binding for more details.
Image uses a smaller <?xml version="1.0" encoding="UTF-8" ?> <info primitiveTypes="element"> <element name="image"> <element name="url" property="URL"/> <addDefaults/> </element> </info> Mapping Item and TextInput
Item
is an example of the other (main) way that mappings are created for objects.
There is no TextInput is also mapped by using introspection. Reading A Bean From XML
|