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:
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(); } }
[edit]Create a XML Document
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.
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");
The result looks like
<xml>
<foo bar="123"/>
</xml>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.