Axaptapedia is now maintained by AgileCadence For more information please click here.
XMLDocument class
XMLDocument class allows to manipulate XML data via DOM.
XMLDocument is a thin wrapper around MSXML in Ax3 and around System.XML .NET framework namespace in Ax4, so use cross refereneces and MSDN to learn about DOM and other stuff.
Example:
<xpp> static void Test_XML(Args _args) {
str xml = @' <tests> <test> <testnumber>1</testnumber> <testname>bla bla</testname> </test> <test> <testnumber>3</testnumber> <testname>asdf</testname> </test> </tests> '; XMlDocument doc=XMLDocument::newXML(xml); XMLNodeList tests = doc.selectNodes('//test'); XMLNode node;
node = tests.nextNode(); while (node) { info(node.selectSingleNode('testnumber').text()); info(node.selectSingleNode('testname').text()); node = tests.nextNode(); }
} </xpp>
Create a XML Document[edit]
You can create you own XML Documents by hand with the XML* Classes. This code creates a XML File with an XML Root element. It has one child element FOO with an attribute BAR. The attributes values is 123. Finally it is stored on C: in file test.xml. <xpp> XMLNode root; XMLElement node; XMLAttribute attr; XMLDocument doc = XMLDOcument::newBlank();
root = doc.createElement("xml"); doc.appendChild(root);
node = doc.createElement("foo"); node.setAttribute("bar","123"); root.appendChild(node);
doc.save("C:/test.xml"); </xpp> The result looks like <xpp> <xml>
<foo bar="123"/>
</xml> </xpp>