Read data from xml file


#1

Hi, I receive an xml file from a webhook that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<root>energy_data 
active_power_TOT="68.41" /></root>

I want to read that 68.41 inside active_power_TOT. How can I do it?


#2

That’s normal string parsing.
Scan for TOT=" and take the portion up to ".

I’d use strstr() for finding the first part and then again strstr() or strpbrk().

Or, if you want the numeric value, locate the beginning (as above) and then take the string after TOT=" into atof() or strtod()

Or you use the way shown in the docs :wink:
https://docs.particle.io/tutorials/topics/webhooks/#the-firmware-1


REST API arguments - is there a better way?
#3

Hi, I partially solved the problem. I’m now able to read inside energy data using the particle docs example, but i can’t read that specific value inside active_power_TOT.


#4

Hi, i’m trying to get data from an xml attribute. I’m using the following example: https://docs.particle.io/tutorials/topics/webhooks/#the-firmware-1
Using this I was able to read part of the xml file, but i can’t isolate the data from that specific attribute. How can I do it?


#5

Did you look at the functions I provided above?
These are all you need to solve the problem.