- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 01:10 AM
<?xml version="1.0" encoding="UTF-8" ?>
<test>
<one>
<two prova="ANNA">A</two>
<three>B</three>
</one>
<one>
<two prova="OSSO">C</two>
<three>D</three>
</one>
</test>
Hi community,
I need to retrieve the attributes from both nodes two: "ANNA" and "OSSO", how can I do this?
I am using XMLDocument2
Thanks you
Andrea
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 03:15 AM
No direct method like XMLDocument to fetch attributes. You can use this one which retrieves by index
var xmlString = "<test><one><two prova='ANNA'>A</two><three>B</three></one><one><two prova='OSSO'>C</two><three>D</three></one></test>";
var xmlDoc = new XMLDocument2(xmlString);
xmlDoc.parseXML( xmlString );
var node = xmlDoc.getNode("//test");
var childNodes = node.getChildNodeIterator();
while(childNodes.hasNext()){
var i = childNodes.next().toString();
var index = i.indexOf("prova");
if(index > -1){
var end = i.indexOf("\">", index);
gs.print(i.substring(index+7, end));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2019 03:55 AM
Thank you,
Andrea