XML file parsing

    Within Dynamics you have a module called the application integration 
    framework which allows you to trade XML messages electronically. 
    Firstly, identify whether this is available via licence.. options to 
    configure AIF for document exchange within the BASIC folder. 
    Unfortunately, cannot seem to attach documents otherwise would send 
    you the instructions.. Can also build XML documents manually using 
    below functionality..
    To create an XML file in Microsoft Dynamics AX, follow these steps: 
    1.      Create a new job. To do this, click Open on the File menu, 
    and then click Application Object Tree. Right-click Jobs, and then 
    click New Job. 
    2.      In the editor, type the following code: 
    static void XMLWriteVendorList(Args _args)
        XMLDocument xmlDoc = XMLDocument::newBlank();
        XMLNode     rootNode;
        VendTable   vendTable;
        VendTransOpen vendtransOpen;
        DialogButton db;
        rootNode = xmlDoc.documentElement();
        rootNode = xmlDoc.appendChild(xmlDoc.createElement('VendorList'));
        db = Box::yesNo('Create VendorList.xml in C/
    \:',Dialogbutton::Yes,'Specify an option');
        if (db == DialogButton::Yes)
            while select vendTable
            join vendtransOpen
            where vendTable.AccountNum==vendtransOpen.AccountNum
                NodeVend = rootNode.appendChild(xmlDoc.createElement
                NodeName = NodeVend.appendChild(xmlDoc.createElement
                NodeAddr = nodeVend.appendChild(xmlDoc.createElement
                NodeCurrency = NodeVend.appendChild(xmlDoc.createElement
                NodeCredit = NodeVend.appendChild(xmlDoc.createElement
    NodeAmount = NodeVend.appendChild(xmlDoc.createElement
    NodeTransDate = NodeVend.appendChild(xmlDoc.createElement
    NodeDueDate = NodeVend.appendChild(xmlDoc.createElement
            Box::info('File created in C:','Operation Finished');
        else if (db==DIalogbutton::No)
            Box::warning('You chose to NOT create the file','Operation 
    3.      Run this job in Microsoft Dynamics AX. When you do this, the 
    following VendorList.xml file is generated:
    <?xml version="1.0" encoding="iso-8859-1" ?> 
      <VendName> Coho Winery </VendName> 
      <VendAddr>1234 W. 5th Ave., Lion, GA 34589</VendAddr> 
      <VendName> Coho Winery </VendName> 
      <VendAddr>1234 W. 5th Ave., Lion, GA 34589 </VendAddr> 
      <VendName> Coho Winery </VendName> 
      <VendAddr>1234 W. 5th Ave., Lion, GA 34589 </VendAddr> 
      <VendName> Northwind Traders </VendName> 
      <VendAddr>456 Main Ave., Robert, MN 98769</VendAddr> 
      <VendName>Tailspin Toys </VendName> 
      <VendAddr>789 Martin St., Smithtown, GA 31095</VendAddr> 
      <VendName>Woodgrove Bank</VendName> 
      <VendAddr>4567 Main St., Buffalo, NY  98052</VendAddr> 
      <VendName> Woodgrove Bank </VendName> 
      <VendAddr>4567 Main St., Buffalo, NY  98052</VendAddr> 
      <VendName> Lucerne Publishing</VendName> 
      <VendAddr>456 North St., Richardville, Canada A1B 2C3</VendAddr> 
    How to read an XML file
    You can use the following methods to read XML files in Microsoft 
    Dynamics AX: 
    •       Read the XML file line by line. When you do this, you can 
    confirm that the correct tags are used for the data. 
    •       Use the microsoft.xmldom COM object. This method is the 
    easiest method.
    To use the microsoft.xmldom COM object to read an XML file that is 
    saved in drive C that is named "VendorList.xml", follow these steps: 
    1.      Create a job. To do this, click Open on the File menu, and 
    then click Application Object Tree. Right-click Jobs, and then click 
    New Job. 
    2.      In the editor, type the following sample code: 
    static void XMLReadVendorList(Args _args)
        XMLDocument     doc;
        XMLParseError   xmlError;
        int i;
        // Read the XML Document
        doc = new XMLDocument();
        // Verify Document Structure
        xmlError  = doc.parseError();
        if(xmlError && xmlError.errorCode() != 0)
            throw error(strFmt("Error: %1",xmlError.reason()));
        // Parsing document contents
        rootNode = doc.documentElement();
        // Get all Vendor information from XML document tags (and remove 
        NodeVend = rootNode.selectSingleNode("//Vendor");
        NodeName = rootNode.selectSingleNode("//VendName");
        NodeAddr = rootNode.selectSingleNode("//VendAddr");
        NodeCurrency = rootNode.selectSingleNode("//VendCurr");
        NodeCredit = rootNode.selectSingleNode("//VendCredit");
        NodeAmount = rootNode.selectSingleNode("//VendAmountCurr");
        NodeTransDate = rootNode.selectSingleNode("//VendTransDate");
        NodeDueDate = rootNode.selectSingleNode("//VendDueDate");
        // From here you can use the retrieved information to insert the 
    data into a temporary table or
        // process the data to obtain  results
        // Print gathered information from XML file
    3.      Run this job in Microsoft Dynamics AX. This code reads the 
    VendorList.xml file that is stored in drive C and then displays the 
    data in an information box. You can do any of the following tasks 
    with the data: 
    •       Insert this data into a temporary table. 
    •       Process this data to obtain results.
    •       Print the data.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.