The CreatorCon Call for Content is officially open! Get started here.

I have XML payload data with me and the output is coming in a single string, all i want is to get the data how I just uploaded a image below where you can see the output "How I Got" and "How I Want" , Can Anyone Help me out to sort out this please.

Raju Kunadharaj
Kilo Explorer

find_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

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

View solution in original post

7 REPLIES 7

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

Hi Simon, 

 

Thankyou so much.  It Worked 

hi pandu, 

 

 

i was also facing same problem:-)