To parse an XML document into a document object tree
Create a
Call the
Objects in the tree are created as transient objects by default because that is generally the way they are used. However, you can create them as shared transient objects (or persistent objects), if required, in which case transaction control is your responsibility.
The following example parses a simple document string into a tree of transient objects:
vars doc: JadeXMLDocument; begin create doc; doc.parseString('<employee>John Smith</employee>'); end;
For an XML string to parse correctly, if an element is prefixed by a namespace, the namespace must be specified. The following line of code results in a parser exception.
doc.parseString('<wx:employee>John Smith</wx:employee>');
To avoid the exception, change the opening tag to the following.
<wx:employee xmlns:wx="http://required_namespace">
To create a tree of persistent objects, you first need to define your own subclasses of all the
vars parser: JadeXMLDocumentParser; doc: MyDocument; begin beginTransaction; create parser; parser.setClassMapping(JadeXMLElement, MyElement); parser.setClassMapping(JadeXMLAttribute, MyAttribute); parser.setClassMapping(JadeXMLText, MyText); parser.setClassMapping(JadeXMLComment, MyComment); parser.setClassMapping(JadeXMLCDATA, MyCDATA); parser.setClassMapping(JadeXMLProcessingInstruction, MyProcessingInstruction); parser.setClassMapping(JadeXMLDocumentType, MyDocumentType); create doc persistent; parser.parseDocumentString(doc, '<employee>John Smith</employee>'); commitTransaction; end;