Monday, 24 March 2014

How to convert Class File to XML file in Ax 2012

static void ClassToXml(Args _args)
{

    SysDictClass sysDictClass  = new SysDictClass(1023902);// used to find the class using classid
    TreeNode    treeNode = TreeNode::findNode(sysDictClass.path()); // to find the class in AOT
    TreeNode    childNode;
    int         counter=1;// used to count No of child nodes in the class
    str         nodename; // used to store the node name
    XmlTextWriter xmlDoc; // used to write xml file

    xmlDoc =XmlTextWriter::newFile("D:\Test.xml"); // creating xml file
    xmlDoc.writeStartDocument(); // writing xml docuemnt starting tag
    xmlDoc.writeStartElement("ClassInformation"); // root node
    xmlDoc.writeAttributeString("ClassName",sysDictClass.name()); // root node attirbutes

    if (treenode) // If  class is avilable
    {
        info(strfmt('number of methods in a classe: %1',treenode.aotchildnodecount()));
        childnode = treenode.aotfirstchild();
        while(counter <= treenode.aotchildnodecount())
        {
            xmlDoc.writeStartElement("MethodInformation");
            xmlDoc.writeAttributeString("MethodName",childNode.treeNodeName());
            xmlDoc.writeElementString("MethodContent",childNode.AOTgetSource());
            xmlDoc.writeEndElement();
            childnode = childnode.aotnextsibling(); // gets the next node
            counter++; // increments the counter by 1
        }
    }
    XMLDoc.writeEndElement(); // writes the End Tag
    xmlDoc.writeEndDocument(); // docuemnt ending.
    info("XML File is Created in D Drive");
}

No comments:

Post a Comment