Re: How to parse this kind of XML
| From: | VamVan | Date: | Thu, 07 Feb 2008 23:44:47 +0000 |
| Subject: | Re: How to parse this kind of XML | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268916@lists.php.net to get a copy of this message | ||
I cannot manipulate the response. this is the response I get from the
web services. is there any other way to do it?
On Feb 7, 2008 3:41 PM, Nathan Nobbe <quickshiftin@gmail.com> wrote:
>
> On Feb 7, 2008 6:17 PM, VamVan <vamseevan@gmail.com> wrote:
>
>
> > Hi,
> >
> > How can I parse this kind of XML data?
> >
> > <event:event>
> >
> >
> > < event:sessionType>9</event:sessionType>
> >
> > <event:hostWebExID>marketingprograms</event:hostWebExID>
> >
> > <event:startDate>05/22/2008 09:00:00</event:startDate>
> >
> > <event:endDate>05/22/2008 10:00:00</event:endDate>
> >
> > <event:timeZoneID>4</event:timeZoneID>
> >
> > <event:duration>60</event:duration>
> > </event:event>
> >
> > I am using SimpleXMLElement function but some cannot retrieve the
> > nodes like timeZoneID for example
>
> you will have to define a namespace in the root node of the xml document;
> then use the SimpleXMLElement::children() method to fetch the nodes in
> that namespace:
>
> $xmlData =
> <<<XMLDATA
> <event xmlns:event="http://fake.com">
>
> <event:sessionType>9</event:sessionType>
> <event:hostWebExID>marketingprograms</event:hostWebExID>
> <event:startDate>05/22/2008 09:00:00</event:startDate>
> <event:endDate>05/22/2008 10:00:00</event:endDate>
> <event:timeZoneID>4</event:timeZoneID>
> <event:duration>60</event:duration>
> </event>
> XMLDATA;
>
> $xml = new SimpleXMLElement($xmlData);
> foreach($xml->children('http://fake.com') as $key
> => $val) {
> echo "$key => $val" . PHP_EOL;
> }
>
> -nathan
>
>