java.lang.Object org.apache.xmlbeans.samples.anytype.AnyA sample that illustrates various ways to manipulate XML whose schema defines elements as type xs:any. Unlike its treatment of other schema types, XMLBeans does not generate accessors for the xs:any particle when compiling schema. Instead, your code handles instances of this type through any of several alternative means, including XPath queries, the selectChildren method, XmlCursor instances and the DOM API. This samples illustrates these alternative approaches.
|Method from org.apache.xmlbeans.samples.anytype.Any Summary:|
|buildDocFromScratch, editExistingDocWithDOM, editExistingDocWithSelectChildren, editExistingDocWithSelectPath, main, parseXml, printErrors, validateXml|
|Methods from java.lang.Object:|
|clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait|
|Method from org.apache.xmlbeans.samples.anytype.Any Detail:|
public boolean buildDocFromScratch()
public boolean editExistingDocWithDOM(RootDocument rootDoc)
public boolean editExistingDocWithSelectChildren(RootDocument rootDoc)
public boolean editExistingDocWithSelectPath(RootDocument rootDoc)
Creates a File from the XML path provided in main arguments, then parses the file's contents into a type generated from schema.
Note that this work might have been done in main. Isolating it here makes the code separately available from outside this class.
public static void printErrors(ArrayList validationErrors)
public static boolean validateXml(XmlObject xml)
Validates the XML, printing error messages when the XML is invalid. Note that this method will properly validate any instance of a compiled schema type because all of these types extend XmlObject.
Note that in actual practice, you'll probably want to use an assertion when validating if you want to ensure that your code doesn't pass along invalid XML. This sample prints the generated XML whether or not it's valid so that you can see the result in both cases.