- 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 02:46 AM
Hi,
Please see the below link:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2018 03:03 AM
Hi,
I am currently using XMLDocument2 is it the same as XMLDocument?
Thanks,
Andrea
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2018 02:49 AM
Hello Andrea,
You can try this out
var doc = new XMLDocument('Your XML String');
var nodes = doc.getNodes('//test/one');
for(var i=0; i < nodes.length; i++){
var value = nodes.item(i).getNodeValue();
gs.print(value);
}
If you need to access node two, then replace
var nodes = doc.getNodes('//test/two');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2018 03:02 AM
Hi,
I am currently using XMLDocument2 is it the same as XMLDocument?
Thanks,
Andrea