web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

XML Parsing

(0) ShareShare
ReportReport
Posted on by

Hi Everyone !

I'm trying to parse xml but every time I loop only the first value is all I can get; and it's posted multiple times. I also tried to use search engine to look for some answers, and also tried to change my codes multiple times but the result is still the same.

Here is the XML that I'm trying to parse via Web Request (I'm using WebRequest to fetch the xml) :

<params>
<param>
<value><array><data>
<value><string>UstId_1</string></value>
<value><string>DE123456789</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>ErrorCode</string></value>
<value><string>212</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>UstId_2</string></value>
<value><string>AB1234567890</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Druck</string></value>
<value><string>nein</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Erg_PLZ</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Ort</string></value>
<value><string>Berlin</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Datum</string></value>
<value><string>04.12.2017</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>PLZ</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Erg_Ort</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Uhrzeit</string></value>
<value><string>06:42:55</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Erg_Name</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Gueltig_ab</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Gueltig_bis</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Strasse</string></value>
<value><string></string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Firmenname</string></value>
<value><string>Test</string></value>
</data></array></value>
</param>
<param>
<value><array><data>
<value><string>Erg_Str</string></value>
<value><string></string></value>
</data></array></value>
</param>
</params>

 

And here is my code to parse the XML :

static void AA_readXMLStringValue(Args _args)
{

        System.Net.WebRequest request;
        System.Net.WebResponse response;
        System.IO.StreamReader respStreamReader;
        str responseXml;

         XMLDocument doc;
         XMLNode paramNode;
         XMLNodeList paramNodeList;
         XMLNodeList AA_param;
         XMLParseError xmlError;
         int i,j,h;
                   
          ;

        request = System.Net.WebRequest::Create("evatr.bff-online.de/evatrRPC;UstId_2=AB1234567890&Firmenname=Test&Ort=Berlin");
        request.set_Method("get");
        request.set_ContentType("text/xml");
        request.set_Timeout(1000);
        response = request.GetResponse();
        respStreamReader = new System.IO.StreamReader(response.GetResponseStream());
        responseXml = respStreamReader.ReadToEnd();

  


         // Get the XML document
         doc = new XmlDocument();
         doc.loadXml(responseXML);
         xmlError = doc.parseError();

         if (xmlError && xmlError.errorCode() != 0)
         {
             print "Error: " + xmlError.reason();
             pause;
             return;
         }
      
        AA_param  = doc.documentElement().childNodes();
       
           For (i = 0; i < AA_param.length(); i++)
           {
                paramNodeList = AA_param.item(i).childNodes();
                    For (j = 0; j < paramNodeList.length(); j++)
                    {
                        paramNodeList = AA_param.item(j).childNodes();
                            For (h = 0; h < paramNodeList.length(); h++)
                            {
                                paramNode = paramNodeList.item(h);
                                info(strFmt('%1', paramNode.innerText()));                              
                            }
                    }
             }

}

 

Thank you in advance !!!

evatr.bff-online.de/evatrRPC;UstId_2=AB1234567890&Firmenname=Test&Ort=Berlin

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Sorry but for correction with request is :

    request = System.Net.WebRequest::Create("https://evatr.bff-online.de/evatrRPC?UstId_1=DE123456789&UstId_2=AB1234567890&Firmenname=Test&Ort=Berlin");

    And also kindly disregard the link after the thank you in advance hehe

    My Bad ! Thank You :)

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I don't think that your intention was taking the value from AA_param in the third for loop.

    Nevertheless using XPath would be likely easier than dealing with many nested loops. Here is a simple example:

    valueNodes = doc.selectNodes('//data/value/string');
    valueNode = valueNodes.nextNode();
    while (valueNode)
    {
        info(valueNode.innerText());
        valueNode = valueNodes.nextNode();
    }


  • Community Member Profile Picture
    on at

    It works !!! Thank You Man !!! :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans