how to read XML

fayez
Tera Contributor

I have XML :

var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+

                                "<parameters><parameter name='message_header' value='head123'/>"

                                "<parameter name='message_content1' value='content123'/>"+

                                "<parameter name='message_content2' value='content456'/></parameters>";

How I can get note value in the script? e.g. get 'message_content2' value 'content456'.

Thanks,

Faye

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

It's more than 2 weeks now, but got some time to look into this. Let try with below code, hope this will help. I was able to print the value in background script.

 

var xmlString = "<?xml version='1.0' encoding='UTF-8'?>"+
"<parameters>"+
"<parameter name='message_header' value='head123'/>" +
"<parameter name='message_content1' value='content123'/>"+
"<parameter name='message_content2' value='content456'/>" +
"</parameters>";

 

var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(xmlString);
var iter = xmlDoc.getNode("//parameters").getChildNodeIterator();
while(iter.hasNext()){
var n = iter.next();
var xmlDoc1 = new XMLDocument2();
xmlDoc1.parseXML(n);
var node = xmlDoc1.getNode("//parameter");
var nodeValue = node.toString().split(' ')[2].split('=')[1].replace(/[^a-zA-Z0-9]/g, "");
gs.print(nodeValue);
}

View solution in original post

7 REPLIES 7

Shishir Srivast
Mega Sage

Please check if this helps: XML APIs


Thanks Shishir. Not work.


Rajesh Mushke
Mega Sage
Mega Sage

Hey Faye,



might be helpful to you.



Please Refer:


How to read in data from an XML file | How To - Step-By-Step Guides To Tasks In LiveCode | LiveCode ...




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Thanks Rajesh.



But it doesn't work.



Thanks,



Faye