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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

parse XML file

Sathishkumar_C
17-Peridot

parse XML file

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 

 

Regards,

Sathishkumar C.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Sathish,

You can directly use xmlDocument.*::meter-timestamp

If it throws error, remove "-" from XML string. You can use below command
XMLString.replace("-","") and try to use
xmlDocument.*::metertimestamp

Regards
Velkumar R

View solution in original post

2 REPLIES 2

Hi Sathish,

You can directly use xmlDocument.*::meter-timestamp

If it throws error, remove "-" from XML string. You can use below command
XMLString.replace("-","") and try to use
xmlDocument.*::metertimestamp

Regards
Velkumar R

It is fine.

i replaced "dcu-timestamp". 

Top Tags