On Wed, 18 Jun 2008 14:45:27 +0200, Captain Paralytic
<pa**********@y ahoo.comwrote:
On 18 Jun, 13:26, David Gillen <bel...@RedBric k.DCU.IEwrote:
>On Tue, 17 Jun 2008 Damodhar <damu...@gmail. comwrote:
Any one help me to parse the bellow xml feed please ..
>============== =============== =============== ===============
><item>
* * * *<title>Green earthquake alert Japan(M=6.8) potentially
affecting 4.6 million people.</title>
* * * *<pubDate>Fri, 13 Jun 2008 23:43 UTC</pubDate>
* * * *<gdas:eventTyp e>EQ</gdas:eventType>
* * * *<gdas:alertLev el>Green</gdas:alertLevel >
* * * *<asgard:alertL evel>Green</asgard:alertLev el>
* * * *<dc:subject>EQ _Green</dc:subject>
</item>
============== =============== =============== ===============
my code :
$xml = new SimpleXMLElemen t($xmldetails);
do $xml = simplexml_load_ string($xmldeta ils);
print_r($xml );
And it'll maybe help you get to the bottom of it.
D.
--
You don't stop playing games because you get old.
You get old because you stop playing games.- Hide quoted text -
- Show quoted text -
How does that square with:
Note: SimpleXML has made a rule of adding iterative properties to most
methods. They cannot be viewed using var_dump() or anything else which
can examine objects.
Yup, parsing errors in SimpleXML, either just catch the errors or use
libXML:
http://nl2.php.net/manual/en/functio...get-errors.php
Then again, if namespaces & prefixed are of importance, DOM is a far
better (allthough heavier) solution. For SimpleXML observe the output of:
<?php
$string = "<item>
<title>Green earthquake alert Japan(M=6.8) potentially
affecting 4.6 million people.</title>
<pubDate>Fri, 13 Jun 2008 23:43 UTC</pubDate>
<gdas:eventType >EQ</gdas:eventType>
<gdas:alertLeve l>Green</gdas:alertLevel >
<asgard:alertLe vel>Green</asgard:alertLev el>
<dc:subject>EQ_ Green</dc:subject>
</item>";
libxml_use_inte rnal_errors(tru e);
$xml = simplexml_load_ string($string) ;
$errors = libxml_get_erro rs();
if(!empty($erro rs)){
foreach ($errors as $error) var_dump($error );
}
libxml_clear_er rors();
//works:
var_dump($xml->eventType);
var_dump($xml->xpath('//eventType'));
//doesn't work as desired
var_dump($xml->{'gdas:eventTy pe'});
var_dump($xml->xpath('//gdas:eventType' ));
//check
echo $xml->asXML();
?>
Mind you, try to repeat that with:
$string = "<item xmlns='http://foobar' xmlns:gdas='htt p://fozbaz'>
<title>Green earthquake alert Japan(M=6.8) potentially
affecting 4.6 million people.</title>
<pubDate>Fri, 13 Jun 2008 23:43 UTC</pubDate>
<gdas:eventType >EQ</gdas:eventType>
<gdas:alertLeve l>Green</gdas:alertLevel >
<asgard:alertLe vel>Green</asgard:alertLev el>
<dc:subject>EQ_ Green</dc:subject>
</item>";
.... it's a whole other issue ;). Wellformed XML is a lot easier to work
with...
///off to work with terrible Facile Forms....
--
Rik Wasmus
....spamrun finished