Axaptapedia is now maintained by AgileCadence For more information please click here.

XMLDocument class

From Axaptapedia
Jump to: navigation, search

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.


<xpp> static void Test_XML(Args _args) {

   str xml = @'
               <testname>bla bla</testname>
   XMlDocument doc=XMLDocument::newXML(xml);
   XMLNodeList tests = doc.selectNodes('//test');
   XMLNode node;
   node = tests.nextNode();
   while (node)
       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);"C:/test.xml"); </xpp> The result looks like <xpp> <xml>

  <foo bar="123"/>

</xml> </xpp>