Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 09:59 PM
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 10:39 PM
Then change the XML payload to:
var xml = current.payload
If you want to bundle your values then use this:
//Just change this payload with "var xml = current.payload;"
var xml = '<results>' +
'<result>' +
'<row>' +
'<nodetest1>test1</nodetest1>' +
'<nodetest2>test2</nodetest2>' +
'</row>' +
'<row>' +
'<nodetest3>test3</nodetest3>' +
'<nodetest4>test4</nodetest4>' +
'</row>' +
'</result>' +
'</results>';
var count = 1;
//Parsing XML string to a xmlDoc
var xmlGrDoc = new XMLDocument2();
xmlGrDoc.parseXML(xml);
//Gets the parent node
var nodes = xmlGrDoc.getNode('//result');
var iter = nodes.getChildNodeIterator();
while(iter.hasNext()){
//Loops through each node
var n = iter.next();
var _row = '';
_row += count + '\n';
//Lets see if its a parent
var rec = n.getChildNodeIterator();
//If parent
while(rec.hasNext()){
//Lets get our row
var row = rec.next();
//Info for each row
_row += 'Node Name ' + row.getNodeName() + ' - Node Value ' + row.getTextContent() + '\n';
//gs.info('Node name: ' + row.getNodeName());
//gs.info('Node Text Content (values): ' + row.getTextContent());
//gs.info('Node value (xml string): ' + row);
}
gs.info(_row);
count++;
}
//In my xml example it will print:
*** Script: 1
Node Name nodetest1 - Node Value test1
Node Name nodetest2 - Node Value test2
*** Script: 2
Node Name nodetest3 - Node Value test3
Node Name nodetest4 - Node Value test4
7 REPLIES 7
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 10:39 PM
Then change the XML payload to:
var xml = current.payload
If you want to bundle your values then use this:
//Just change this payload with "var xml = current.payload;"
var xml = '<results>' +
'<result>' +
'<row>' +
'<nodetest1>test1</nodetest1>' +
'<nodetest2>test2</nodetest2>' +
'</row>' +
'<row>' +
'<nodetest3>test3</nodetest3>' +
'<nodetest4>test4</nodetest4>' +
'</row>' +
'</result>' +
'</results>';
var count = 1;
//Parsing XML string to a xmlDoc
var xmlGrDoc = new XMLDocument2();
xmlGrDoc.parseXML(xml);
//Gets the parent node
var nodes = xmlGrDoc.getNode('//result');
var iter = nodes.getChildNodeIterator();
while(iter.hasNext()){
//Loops through each node
var n = iter.next();
var _row = '';
_row += count + '\n';
//Lets see if its a parent
var rec = n.getChildNodeIterator();
//If parent
while(rec.hasNext()){
//Lets get our row
var row = rec.next();
//Info for each row
_row += 'Node Name ' + row.getNodeName() + ' - Node Value ' + row.getTextContent() + '\n';
//gs.info('Node name: ' + row.getNodeName());
//gs.info('Node Text Content (values): ' + row.getTextContent());
//gs.info('Node value (xml string): ' + row);
}
gs.info(_row);
count++;
}
//In my xml example it will print:
*** Script: 1
Node Name nodetest1 - Node Value test1
Node Name nodetest2 - Node Value test2
*** Script: 2
Node Name nodetest3 - Node Value test3
Node Name nodetest4 - Node Value test4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 11:22 PM
Hi Simon,
Thankyou so much. It Worked
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2018 10:49 PM
hi pandu,
i was also facing same problem:-)