how parse a simple serial data

14 Apr 2011

hi,

This is a string : "<tmpr>18.7</tmpr><sensor>1</sensor><watts>00345</watts>...."

I would like get the different value in this string. I'm sur there is a simple way, but as i'm a neewb in this language... I didn't find.

Thanks for the help.

14 Apr 2011

Hi

Where is this going, to the embed or comoing from the embed.

On a PC you could load it into a XmlDocument and have it do the decoding for you. On the mbed there is no Xml Support so you need to decode by hand (in which case Xml isn't a handy format).

14 Apr 2011

oups, i get this string IN (by pin 10) from a serial communication So i need to parse it on the mbed card.

Ok to decode by hand, but is there a way to get a part of string between 2 different delimiters ? for exemple : <sensor> and </sensor>

thanks

14 Apr 2011

you can write a code to extract the values between delimiters but its going to be a lot harder than having a delimiter like +, :, =, _ etc. Point is, if theres a way to recode your string to use a more simpler delimiter like above, it will be a lot easier for you

15 Apr 2011

Hi,

I'm currently importing a number of (small) xml parsers to see if they compile.

I already compiled tinyxml with success but need to do some further testing before i turn it into a library.

Wim

15 Apr 2011

Thanks ;)

Herson Bagay wrote:

you can write a code to extract the values between delimiters but its going to be a lot harder than having a delimiter like +, :, =, _ etc.if theres a way to recode your string to use a more simpler delimiter like above, it will be a lot easier for you

Ok, but how doing this ?

Unfortunetely, i can't rewrite this code that come from another system...

Yann

16 Apr 2011

well, its like writing a parser, only you have to specify the delimiters (in which case, strings themselves). I really can't tell you how to code it because I haven't done any XML parsing code before but its possible if you have the time and effort.

17 Apr 2011

you can modify this function for your application:

void split(const string& s, char c,
           vector<string>& v) {
    string::size_type i = 0;
    string::size_type j = s.find(c);
    while (j != string::npos) {
        v.push_back(s.substr(i, j-i));
        i = ++j;
        j = s.find(c, j);
        if (j == string::npos)
            v.push_back(s.substr(i, s.length( )));
    }
18 Apr 2011

Hi,

I've ported the TinyXml library to an mbed library. It allows Xml Parsing and manipulation and much more without a large memory footprint. See TinyXML Topic.