Search code examples
xmlaxaptax++dynamics-ax-2009xmlnode

Selecting XML Node and its children. Thereby getting their values X++, AX09


My XML code is:

<ParentNode> <Node> <Name1>2003</Name1> <Name2>20030630</Name2> <Name3>20140225</Name3> <Name4>46944000</Name4> <Name5>94750099</Name5> </Node> </ParentNode> ' But i can't the values of name1, name2 etc. I have tried almost everything, but it comes up empty or XMLNode not initzialied

I have been told to use selectSingleNode so i have tried everything it: info(strfmt("%1",levelOne.selectSingleNode('//Name1'))); info(strfmt("%1",levelOne.selectSingleNode('Node/Name1'))); But nothing works


Solution

  • Have a look at the code below - this will print '2003' to the infolog.

    public static client void SomeAotJob()
    {
        str xml;
        XmlDocument xmlDoc;
        XmlNode xmlNode;
        ;
    
        xml = @'<ParentNode>
        <Node>
            <Name1>2003</Name1>
            <Name2>20030630</Name2>
            <Name3>20140225</Name3>
            <Name4>46944000</Name4>
            <Name5>94750099</Name5>
        </Node>
    </ParentNode>';
    
    
        xmlDoc = XmlDocument::newXml(xml);
        xmlNode = xmlDoc.selectSingleNode('//Name1');
        info(xmlNode.innerText());
    }