- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 02:36 AM
<?xml version="1.0" encoding="UTF-8" ?>
<test>
<one>
<two>A</two>
<three>B</three>
</one>
<one>
<two>C</two>
<three>D</three>
</one>
</test>
Hi Community,
Can you please help me to retrieve data "A" and "C" from the correspondent childNodes "two" when the parentNode has the same name. See the example above.
Thanks,
Andrea
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 03:17 AM
Please try this out, I have tested
var xmlString = "<test><one><two>A</two><three>B</three></one><one><two>C</two><three>D</three></one></test>";
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML( xmlString );
node = xmlDoc.getFirstNode( '//test/one/two' );
j=1;
while( node != null ) {
var value = xmlDoc.getNodeText( '//test/one[' + j + ']/two');
gs.info( 'Value: ' + value);
j++;
node = xmlDoc.getNextNode( node );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 03:17 AM
Please try this out, I have tested
var xmlString = "<test><one><two>A</two><three>B</three></one><one><two>C</two><three>D</three></one></test>";
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML( xmlString );
node = xmlDoc.getFirstNode( '//test/one/two' );
j=1;
while( node != null ) {
var value = xmlDoc.getNodeText( '//test/one[' + j + ']/two');
gs.info( 'Value: ' + value);
j++;
node = xmlDoc.getNextNode( node );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 03:37 AM
Hi
your code is correct, i don't manage to reproduce it with my xml which is actually more complicated than the example I provided above.
Thanks.
Andrea
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2019 05:18 AM
Hi,
do you know how to retrieve attributes using xmldocument2?
Andrea

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2018 02:51 AM
you can try this kind of sample test on "www.w3schools.com", they have explained very well
adding one link here, it has one example to get the child node value.
Example : https://www.w3schools.com/xml/tryit.asp?filename=try_dom_nodelist