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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Problem with XML (parsing)

tcoufal
12-Amethyst

Problem with XML (parsing)

Hi guys,

I have problem with parsing the XML get response.

I have tried every approach which I could find. (here or anywhere else).

It drives me crazy because it is a very simple XML. Here it is.

<?xml version="1.0" encoding="utf-8"?>

<LL control="dev/sps/io/Power/state" value="5.07kW" Code="200"/>

I am getting the result with GetXML (LoadXML works the same), but when I am trying parse the Value out of it, it always returns empty (as none). I am accessing the value with resultXml.LL.@value. (.@code, .@control -- all empty). I have tried to iterate and push the results  into the array - nothing. XML is not using namespaces. If I use warn.log it is also empty. I have tried different Base types. Nothing. Strange is that if I set the result to XML and use var result = Resources[]..... I can see the result while running service through the REST API, but if I try logger.warn(xmlResult) it is also blank.

1 ACCEPTED SOLUTION

Accepted Solutions
paic
1-Newbie
(To:tcoufal)

Maybe try resultXml.@value

else resultXml.*::LL.@value maybe resultXml.*::LL.*::@value

Sorry if these don't work, the second one is a basic way of trying to escape Name spaces.

View solution in original post

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

Maybe try resultXml.@value

else resultXml.*::LL.@value maybe resultXml.*::LL.*::@value

Sorry if these don't work, the second one is a basic way of trying to escape Name spaces.

tcoufal
12-Amethyst
(To:paic)

Hi Pai,

the first one did it

And I thought I have tried that one.

Still dont get why it cannot be accessed with "LL" (perhaps its a parent or root node?)

Thank you though.

paic
1-Newbie
(To:tcoufal)

Correct root node is skipped.

Hi,

is there any way to access tags with variable?

My Sample file is "xmlDocument":

 

<reading xmlns="http://cyantechnology.com/dean/v1">
<link href="https://cyan-hes-vip-master:8000/v1/readings/824cde15-f6b6-4819-abbe-8524d16f2972" method="delete" rel="delete"/>
<link href="https://cyan-hes-vip-master:8000/v1/readings/824cde15-f6b6-4819-abbe-8524d16f2972" method="get" rel="reading"/>
<link href="https://cyan-hes-vip-master:8000/v1/dcus/969c515f-cf50-4861-8029-3070e891937b" method="get" rel="dcu"/>
<link href="https://cyan-hes-vip-master:8000/v1/meters/91b69412-f06d-45e4-83a3-6fce6694c3bb" method="get" rel="meter"/>
<meter-serial-number>17254120</meter-serial-number>
<meter-timestamp unit="iso8601">2018-01-23T20:26:15Z</meter-timestamp>
<dcu-timestamp unit="iso8601">2018-01-23T20:26:15Z</dcu-timestamp>
<rtc unit="iso8601">2018-01-24T01:53:54-00:00</rtc>
<configuration_manufacturer>Larsen & Toubro Limited</configuration_manufacturer>
<configuration_serial>S17254120</configuration_serial>
<configuration_firmware_version>7PB0L.60</configuration_firmware_version>
<reading/>

if i want to read "configuration_manufacturer" data. i ll use below one.

 

result = xmlDocument.*::configuration_manufacturer

 

Like this how can i read "meter-timestamp" data?

Is anyway to access with variable?

 

var tag = "meter-timestamp";
result = xmlDocument.*::tag 

 

Top Tags