Below code helps to parse the XML file in AX using X++ code, This is very simple approach and also eliminates namesspace like., xmlns:
static void XMLTextReader(Args
_args)
{
    XMLNodeType nodeType;
    XmlTextReader xmlReader;
    System.IO.StreamReader      reader;
    str                         xml;
    ;
    reader          = new
System.IO.StreamReader(@'C:\Users\Test.xml');
    xml             = reader.ReadToEnd();
    xmlReader = XmlTextReader::newXml(xml);
   
xmlReader.whitespaceHandling(XmlWhitespaceHandling::None);
    xmlReader.moveToContent();
    while (xmlReader.read())
    {
        switch (xmlReader.nodeType())
        {
            case XMLNodeType::Element:
               
info(strfmt("%1",xmlReader.name()));
                info(strfmt("%1",xmlReader.value()));
                break;
            case XMLNodeType::Text:
               
info(strfmt("%1",xmlReader.value()));
                break;
            case XMLNodeType::XmlDeclaration:
            case
XMLNodeType::ProcessingInstruction:
               
info(strfmt("%1",xmlReader.name() + " " +
xmlReader.value()));
                break;
            case XMLNodeType::Comment:
               
info(strfmt("%1",xmlReader.value()));
                break;
            case XMLNodeType::EndElement:
                break;
        }
    }
}
 
No comments:
Post a Comment