Re: Parsing an XML return from a POST - resend with a little more information
| From: | Jochem Maas | Date: | Wed, 10 Jan 2007 08:38:30 +0000 |
| Subject: | Re: Parsing an XML return from a POST - resend with a little more information | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246830@lists.php.net to get a copy of this message | ||
Richard Luckhurst wrote:
> Hi Jochem,
>
> Thanks for your reply. Here is a short sample of the XML I have to parse. I need
> the data in the attributes as well as the data in the character fields.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <?ypsilon RNGSchema="fareResponse.rnc" type="compact"?>
I'm fairly certain that this 'ypsilon' tag is going to cause a
problem - although that's just a guess, it's based on the 'knowledge'
that a valid XML document *must* have only 1 root element
(which would be 'fareResponse' in this case).
you might have to use preg_replace() to strip this 'ypsilon' tag
from you xml stgring prior to feeding it into simpleXML (or other
XML parser).
e.g. something *like*:
$xml = preg_replace('#<\?ypsilon .*\?>#', '', $xml);
> <fareResponse cntTarifs="122" offset="0">
...
> </fareResponse>
>
>
>
>
> JM> me, I'm pretty convinced simpleXML is what he wants.
>
> JM> simpleXML was a dog to use in earlier versions of php5 because simpleXML objects
> JM> were 'immune' to inspection by var_dump(), print_r(), etc [meaning you be told
> JM> some
> JM> property was an array and then get an error if you access said property as an array,
> JM> stuff like that].
>
> JM> those problems have been helped the way of the dodo so now simpleXML really does
> JM> what it says on the tin.
>
> JM> of course there is always the options of using regular expressions or simple
> JM> string manipulation functions to extract the relevant data from the string of
> JM> 'xml' - technically there is no need to go anywhere near a 'real'
> JM> xml parser
> JM> as such.
>
> So far I have had no luck with simpleXML at all.
do as Roman says and post the simpleXML code you have so far.
>
> Regards
>
> Richard Luckhurst
>