Hello Service-now Diary,
Its very difficult for me to understand this very difficult recursive function for processing XML given in this location CommunitySnippet
All that I want to do is I have a XML document and I want to process it.
Regards, Hiranya
Dear Hiranya,
That example is a very good way to process complex XML, But then it may seem tough,especially if you are in hurry! ;)
TO cover the basic stuff to access a Node:
xmldoc.getNodeText(“
Now the entire process of processing the XML comes down to simple two steps, 1.Identifying the node(nodes) you want to use the value 2.Using anyof the method to get the value of the node.
Also,You can store the Node pointers in arrays,by using the getNodes() method( ,and process it using a while or for loop. For example, Supposing this is the Structure of XML You want to process is something like this
something
something
something
something
something
something
something
something
[/code]
The code will be something like this
[code][/code]
var i=1;
var arr = [];
var check = xmldoc.getNodeText("//child[1]");
while(check != null){
for(var j=1;j<=5;j++){
var a =xmldoc.getNodeText("//child["+i+"]/grandchild["+j+"]/*");
arr[j]= a;
}
i++;
var check = xmldoc.getNodeText("//child[i]");
}
This is a basic code. You can count the nodes as well and use them in the loops.But I feel this ways clean,the oldschool’s way with less functions and more code ;-)
Hope this helped hiranya.
Cheers, Service-Now Diary
-