Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming you have all of the feed in memory, I would write a very crude, and simple, parser.</p> <p>First, I'd write a high level tokenizer. This tokenizer would return two types of tokens: XML Tags and Other.</p> <p>So, if you had as a XML source:</p> <pre><code>&lt;tag arg="stuff"&gt; &lt;tag2&gt;data&lt;/tag2&gt; &lt;/tag&gt; That would return "&lt;tag arg="stuff"&gt;" as the first token, " " (note newline) in the second token, "&lt;tag2&gt;" in the third, "data" in the forth. </code></pre> <p>Something like this:</p> <pre><code>char *p = bufPtr; char *start = p; char *token; char target; if (*p == '&lt;') { // found the start of a tag, lets look for the end target = '&gt;'; } else { // not in a tag, so we'll search for one target = '&lt;'; } p++; while (*p != target) { p++; } int length = p - start; result = malloc(length + 1); memcpy(result, start, length); *(token + length) = '\0'; // terminate result string bufPtr = p; // advance for the next token </code></pre> <p>(caveat, my C is rusty, there may well be some one off errors in here, but the gist is good.)</p> <p>Now that I'm getting these meta chunks of the XML, it's straightforward.</p> <p>I just scan tokens until I see one that starts with your geo tag. Once you see this, you "know" the next token is your lat/long data. Grab that, parse it (perhaps with sscanf), to get your values.</p> <p>What this does is effectively flatten you XML space. You don't really care how deep the tag is, and you really don't care it's well formed, or anything. You're pretty much assuming it's well formed and conforming.</p> <p>Of the top of my head, I don't know if XML allows the &lt; or > chars within a quoted tag attribute, but even if it does allow it, odds are good that this SPECIFIC XML does not, so it'll work. Otherwise you'll need to parse quoted stuff (not that much harder, but...).</p> <p>Is this robust? Hell no. Very GIGO sensitive. But a simple check to make sure you don't run off the buffers end should save you there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload