Example
Code of a method referenced by an MDAC command
JDOM_Parser lParser;
JDOM_Node lRoot;
JDOM_Document lDoc;
String lName;
sessionBegin("loadXMLFile",true);
lParser = JDOM_Parser.create();
lParser.setValidationScheme(true);
lParser.setDoNamespaces(true);
lParser.setExitOnFirstFatalError(false);
lParser.setValidationConstraintFatal(false);
lParser.setIncludeIgnorableWhitespace(true);
lParser.parse("/tmp/MyFile.xml");
if (lParser.sawErrors() == true)
{
StdOut.write("Status parser
1 = ",
lParser.getErrors(),NL);
}
lDoc = lParser.getDocument();
if (notVoid(lDoc))
{
StdOut.write(" --- Document
successfully
retrieved!",NL);
lRoot =
lDoc.getDocumentElement();
if (notVoid(lRoot))
{
lName = lRoot.getNodeName();
StdOut.write(" --- Retrieving the root element ~"",
lName, "~" successful
!",NL);
lRoot.<recursiveGetChilds();
}
else
StdOut.write(" ---
Impossible to retrieve the root
element!",NL);
}
lDoc.printXML("/tmp/modules.xml");
lDoc.delete() ;
sessionEnd();
Code of the recursiveGetChilds method (defined on the JDOM_Node metaclass)
JDOM_Node[] lChilds;
JDOM_Node[] lAtts;
StdOut.write("-----------------------------------------
------------------",NL);
getChildNodes(lChilds);
lChilds
{
StdOut.write(" ---
Retrieving the element ~"",
getNodeName(), "~"
:",NL);
StdOut.write(" ---
Retrieving the composed
element ~"",
getParentNode().getNodeName(), "~"
:",NL);
if (getNodeType() == JNODE_NONE)
{
StdOut.write(" --- Text
= ", getNodeValue(),NL);
}
getAttributes(lAtts);
lAtts
{
StdOut.write ("Attribute =
", getNodeName(),
" Value = ",
getNodeValue(), NL);
setNodeValue(getNodeValue()+"_NewValue");
}
lAtts.clear();
recursiveGetChilds();
}