1

For a program I am working on I need to get info from a specific area from an online xml document. Right now I have save the xml as a string and then use press=xml.substr(1906,5); to get what I need from it. This is one line I pull info from: <pressure_in>30.17</pressure_in> The problem with this is that if the value between is longer than the specified length, (5 characters in this case) I cant get the desired value. How could I get it reliably?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Cameron346
  • 21
  • 3
  • 3
    [Use a real XML parser?](http://stackoverflow.com/questions/9387610/what-xml-parser-should-i-use-in-c) – WhozCraig Dec 02 '13 at 01:02
  • If you're able to get that line without an full blown XML parser, just use a simple regular expression. – turnt Dec 02 '13 at 01:06

2 Answers2

1

First convert the string to an xml structure, then extract what you need with an XPath selector. A very simple example can be found here:

http://xmlsoft.org/tutorial/apd.html

peterh
  • 11,875
  • 18
  • 85
  • 108
1

Have you considered something like this:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main ()
{
    // sample string below:
    char* xmlText = "<pressure_in>30.17134</pressure_in>";
    int n = strlen(xmlText);
    for (int i = 0; i<n; i++) {
        if (isdigit(xmlText[i]) || xmlText[i] == '.') {
            // store result or just print:
            printf("%c",xmlText[i]);
        }
    }
    printf("\n")
    return 0;
}

Output:

30.17134
Bruce Dean
  • 2,798
  • 2
  • 18
  • 30