blob: 40a2de3c8ef7374f62af56f5ba97664477beb4c5 [file] [log] [blame]
Sample: MixedContent
Author: Steven Traut (straut@bea.com)
Last Updated: Sept. 6, 2004
Versions:
xmlbeans-1.0.3
xmlbeans-v2
-----------------------------------------------------------------------------
This sample illustrates how you can work with mixed content XML by combining
strong types generated from schema with an XmlCursor instance. The XmlCursor
interface is provided with XMLBeans for just this kind of use. With strong types
you can only get or set the full value of an element; by using a cursor you can
"dive into" the contents of an element, manipulating child elements that are
embedded in the content and surrounded by other text.
The sample's XML is a pseudo-inventory of nonsensical items, each with a unique
ID and a description. Where the name of one item is mentioned in the description
of another, the sample code wraps the name with a <link> element whose id
attribute is the ID of the named item.
When you run this sample, you'll see it print potentially three blocks of
information:
- The XML it got from the inventoryitems.xml file.
- The XML it generated by associating cross-mentioned items.
- The results from validating the resulting XML, if the XML is invalid.
To try out this sample:
1. Set XMLBEANS_HOME in your environment
2. Ant must be on your PATH
3. To compile the schemas and sample source, run "ant build"
4. To execute the sample, run "ant run"