<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question getChildNodeIterator() iteration more than no of entries in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201147#M856619</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have request body, where multiple nodes can be there in request body xml. But when I am iterating it using&amp;nbsp;getChildNodeIterator(), it is iterating more times than number of entries parent node has.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the below scenario, logs occurring 6-7 times, when Request body has only one &amp;lt;x:systemResponse&amp;gt; node.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I even tried replacing the statement&amp;nbsp;var sysResp = xmlDoc.getNode('//x:targetResponse') by&amp;nbsp;var sysResp = xmlDoc.getNode('//x:systemResponse'), but same situation was there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Request Body XML:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV id="collapsible3" class="collapsible"&gt;
&lt;DIV class="expanded"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:execute&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:targetResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="comment html-comment"&gt;&amp;lt;!-- 1 or more repetitions: --&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV id="collapsible4" class="collapsible"&gt;
&lt;DIV class="expanded"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:systemResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:system&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;SAP&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:system&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:type&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;S&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:type&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:message&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;Error Removed&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:message&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:systemResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:targetResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:execute&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;STRONG&gt;&lt;SPAN class="html-tag"&gt;Processing Script:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;var xmlDoc = new XMLDocument2();&lt;BR /&gt; xmlDoc.parseXML(reqXML);&lt;BR /&gt; var sysResp = xmlDoc.getNode('//x:targetResponse');&lt;BR /&gt; var iter = sysResp.getChildNodeIterator();&lt;BR /&gt; &lt;BR /&gt; while(iter.next()) {&lt;BR /&gt; var system=xmlDoc.getNodeText('//x:system');&lt;BR /&gt; var type=xmlDoc.getNodeText('//x:type');&lt;BR /&gt; var msg=xmlDoc.getNodeText('//x:message');&lt;BR /&gt; gs.info("System = "+system+"\nType = "+type+"\nMsg = "+msg);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;Appreciate your quick response.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;Thanks you.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 16 Jan 2019 10:39:20 GMT</pubDate>
    <dc:creator>priyankapalaska</dc:creator>
    <dc:date>2019-01-16T10:39:20Z</dc:date>
    <item>
      <title>getChildNodeIterator() iteration more than no of entries</title>
      <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201147#M856619</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have request body, where multiple nodes can be there in request body xml. But when I am iterating it using&amp;nbsp;getChildNodeIterator(), it is iterating more times than number of entries parent node has.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the below scenario, logs occurring 6-7 times, when Request body has only one &amp;lt;x:systemResponse&amp;gt; node.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I even tried replacing the statement&amp;nbsp;var sysResp = xmlDoc.getNode('//x:targetResponse') by&amp;nbsp;var sysResp = xmlDoc.getNode('//x:systemResponse'), but same situation was there.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Request Body XML:&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV id="collapsible3" class="collapsible"&gt;
&lt;DIV class="expanded"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:execute&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:targetResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="comment html-comment"&gt;&amp;lt;!-- 1 or more repetitions: --&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV id="collapsible4" class="collapsible"&gt;
&lt;DIV class="expanded"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:systemResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="collapsible-content"&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:system&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;SAP&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:system&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:type&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;S&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:type&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;x:message&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="text"&gt;Error Removed&lt;/SPAN&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:message&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:systemResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:targetResponse&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;&amp;lt;/x:execute&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;STRONG&gt;&lt;SPAN class="html-tag"&gt;Processing Script:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;var xmlDoc = new XMLDocument2();&lt;BR /&gt; xmlDoc.parseXML(reqXML);&lt;BR /&gt; var sysResp = xmlDoc.getNode('//x:targetResponse');&lt;BR /&gt; var iter = sysResp.getChildNodeIterator();&lt;BR /&gt; &lt;BR /&gt; while(iter.next()) {&lt;BR /&gt; var system=xmlDoc.getNodeText('//x:system');&lt;BR /&gt; var type=xmlDoc.getNodeText('//x:type');&lt;BR /&gt; var msg=xmlDoc.getNodeText('//x:message');&lt;BR /&gt; gs.info("System = "+system+"\nType = "+type+"\nMsg = "+msg);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;Appreciate your quick response.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="line"&gt;&lt;SPAN class="html-tag"&gt;Thanks you.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Jan 2019 10:39:20 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201147#M856619</guid>
      <dc:creator>priyankapalaska</dc:creator>
      <dc:date>2019-01-16T10:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: getChildNodeIterator() iteration more than no of entries</title>
      <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201148#M856620</link>
      <description>&lt;P&gt;Hi Priyanka,&lt;/P&gt;
&lt;P&gt;I believe that is because of the namespace prefix i.e. x&lt;/P&gt;
&lt;P&gt;May be you can create a script include in global scope and pass the xml string, parse it and return whatever you want. in that way you would be able to achieve&lt;/P&gt;
&lt;P&gt;Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 09:42:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201148#M856620</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2019-01-17T09:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: getChildNodeIterator() iteration more than no of entries</title>
      <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201149#M856621</link>
      <description>&lt;P&gt;Hi Ankur,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually we may have multiple &amp;lt;x:systemResponse&amp;gt; nodes, therefore we are applying child node iterator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and in the loop, if we have 2 child nodes, it can only able to search one and iterate it multiple (6-7) times.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 10:40:31 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201149#M856621</guid>
      <dc:creator>priyankapalaska</dc:creator>
      <dc:date>2019-01-17T10:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: getChildNodeIterator() iteration more than no of entries</title>
      <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201150#M856622</link>
      <description>&lt;P&gt;Hi Priyanka,&lt;/P&gt;
&lt;P&gt;The issue is because of namespace, so better way is to handle this using the global scope.&lt;/P&gt;
&lt;P&gt;Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.&lt;BR /&gt;Thanks&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 11:22:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201150#M856622</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2019-01-17T11:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: getChildNodeIterator() iteration more than no of entries</title>
      <link>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201151#M856623</link>
      <description>&lt;P&gt;Hi Priyanka,&lt;/P&gt;
&lt;P&gt;Any update on this?&lt;BR /&gt;Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.&lt;BR /&gt; &lt;BR /&gt;Regards&lt;BR /&gt;Ankur&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 08:12:53 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getchildnodeiterator-iteration-more-than-no-of-entries/m-p/2201151#M856623</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2019-02-12T08:12:53Z</dc:date>
    </item>
  </channel>
</rss>

