Hello!
I need to read an XML feed from a URL and output it to plain text without excessive whitespaces - preferably to a file, but initially output to screen would be OK.
For example, can I use MagicParser to change a feed that looks like this:
<?xml version="1.0" ?>
<Coaches>
<name>New York CS</name>
<address>New York Coach Station, 164 New York Palace Road</address>
<state>New York</town>
<zipcode>11234</postcode>
<telephone />
<opening_times />
</Coaches>
into this:
New York CS
New York Coach Station, 164 New York Palace Road
New York
11234
I am building a web application using PHP that needs to parse XML feeds.
I have only discoved XML recently and after trying to write a parser, one of the irritating things that I cannot resolve is lots of leading whitespace - meaning that my result looks like this:
New York CS
New York Coach Station, 164 New York Palace Road
New York
11234
If MagicParser can sort this for me, let me know?
Thanks,
RodThePlod
Hi Rod,
Do you know about PHP's trim() function? That may be all you need to turn the output from your own parser into what you want as it will strip white space from either end of a string.
If the output from your own parser is producing a single string, you could break it down into lines using explode() first and then strip the white space with trim().
Thanks for the quick reply!!!
I tried using trim() last night and that seemed to concatenate all of the elements into one big block. So it seems as though I am actually parsing everything out into one line as you suggest.
So... I have a look at explode() and see if this can help me!
Thanks again David!
RodThePlod
Suprisingly, all the whitespace in my second example has been removed when clicking on 'post'!
Hopfully, you'll know what I mean. If I can find an contact email for you, I'll use that instead
Thanks,
RodThePlod