cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How to access XML attributes

joshuahes
1-Newbie

How to access XML attributes

I have loaded some XML from an external source and the info I need is listed as an attribute on the xml group node.

How can the script access the XML attributes using the getXML snippet. I have tried accessing it with brackets "group["name"]" with no luck

example XML: <groups>

   

<

group

name

= "name1"

>url<

/group

>

   

<

group

name

= "name2"

>url<

/group

>

    ...

I'm unsure how to access the attribute name using the getXML code. I am able to retrieve the url so I know that part of the code is working.

CODE:

var configXML = Resources["ContentLoaderFunctions"].GetXML(params);

var groups = [];

for each (var group in configXML.groups.group){

    groups.push(group);

}

var result = groups.join(",");

4 REPLIES 4
paic
1-Newbie
(To:joshuahes)

Hi Josh, 

try

for each (var group in configXML.groups.group) {

groups.push(group.@name)

}

var result = groups.join(",");


if that doesn't work, try group.name but I think .@name is what you need.



Hi Pai Please how can i access the elements (Id, numero-escale ....)

Capture.PNG

Yup group.@name did it!

Thank you!



Hi Joshua/Pai,

I need one help. I have an URL. Whenever you will hit the URL ,it will generate dynamic XML based upon the User Selection. But problem is , the XML i am getting or getting generated by ThingWorx contains some unwanted filed provided by Thingworx. How can i am write the query so that i can get the correct format of XML. Below i have given one snapshot of generated XML where i need the highlighted tags as an output from the URL. I want to know what kind of service shall i write so that i will get my required output in URL in XML format. I just wanted the highlighted XML tags only.

Thanks & Regards:

kshirod

Announcements


Top Tags