- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2015 06:19 PM
Chris thank you so much for your help. The part I needed was the .getTextContent().
Here is what i have done so far.
Since the nodes could contain 3-5 child nodes i created a series of "if" statements to see which child node i have landed on and then map that value to a correct variable:
var node = xmlDoc.getNode('//HOST');
//gs.log(node.toString());
var iter= node.getChildNodeIterator();
//vars for mapping
var id = '';
var ip = '';
var track = '';
var dns = '';
var net = '';
var os = '';
while(iter.hasNext){
var n = iter.next();
//gs.log('Node name: ' + n.getNodeName());
var name = n.getNodeName();
if(name === 'ID'){
id = n.getTextContent();
gs.log("ID is: " + id);
}
if(name === 'IP'){
ip = n.getTextContent();
gs.log("IP is: " + ip);
}
if(name === 'TRACKING_METHOD'){
track = n.getTextContent();
gs.log("Track is: " + track);
}
if(name === 'DNS'){
dns = n.getTextContent();
gs.log("DNS is: " + dns);
}
if(name === 'NETBIOS'){
net = n.getTextContent();
gs.log("NetBios is: " + net);
}
if(name === 'OS'){
os = n.getTextContent();
gs.log("OS is: " + os);
}
}
This brings me a nice clean output of my vars = the data from the child nodes or null if there was no value for it.
Now the fun part. You mentioned using:
var host1 = xmlDoc.getNode('//HOST');
var host2 = xmlDoc.getNode('//HOST[2]);
var host3 = xmlDoc.getNode('//HOST[3]);
How would i go about iterating through that using a for loop?
for(var i = 0; i < what goes here????;i++){
var node = xmlDoc.getNode('//HOST[i]');
I tired:
for(var i = 0; i < node.length;i++){
var node = xmlDoc.getNode('//HOST[i]');
but that returned nothing.
I don't really know which variable is the array, or if one really exists here.