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

Omkar Mone
Mega Sage

Hi 

Can you show you code or the way you're displaying it?

Hi Omkar, 

Below is the Code which I wrote in Business Rule of ECC Queue

 

(function executeRule(current, previous /*null when async*/) {

var gt = current.payload;
gs.addInfoMessage(gt);     // single string 
var name = gs.getXMLText(current.payload, "//u_user");
gs.addInfoMessage(name);  // first occurance value in the u_user tag of xml


})(current, previous);

 

Thanks in Advance.

Simon Christens
Kilo Sage

Hi

Try something like this:

	var xml = '<results>' +
	'<result>' +
	'<row>' +
	'<test1>test1</test1>' +
	'<test2>test2</test2>' +
	'</row>' +
	'<row>' +
	'<test3>test3</test3>' +
	'<test4>test4</test4>' +
	'</row>' +
	'</result>' +
	'</results>';
	
	//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();
		//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
			gs.info('Node name: ' +   row.getNodeName());
			gs.info('Node Text Content (values): ' + row.getTextContent());
			gs.info('Node value (xml string): ' + row);
		}
	}

*** Script: Node name: test1
*** Script: Node Text Content (values): test1
*** Script: Node value (xml string): <test1>test1</test1>
*** Script: Node name: test2
*** Script: Node Text Content (values): test2
*** Script: Node value (xml string): <test2>test2</test2>
*** Script: Node name: test3
*** Script: Node Text Content (values): test3
*** Script: Node value (xml string): <test3>test3</test3>
*** Script: Node name: test4
*** Script: Node Text Content (values): test4
*** Script: Node value (xml string): <test4>test4</test4>

 

 

Hi Simon,

 

I can't assign the XML payload data manually,

Tell me any Solution using current.payload.

 

Thanks in Advance