PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Parse the XML feed me
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Parse the XML feed me

Réponse
 
LinkBack Outils de la discussion
Vieux 17/06/2008, 07h47   #1
Damodhar
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Parse the XML feed me


Any one 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:eventType>EQ</gdas:eventType>
<gdas:alertLevel>Green</gdas:alertLevel>
<asgard:alertLevel>Green</asgard:alertLevel>
<dc:subject>EQ_Green</dc:subject>
</item>
================================================== =========

my code :
$xml = new SimpleXMLElement($xmldetails);
foreach($content->item as $details)
{
$desaster_title = $details->title;
$description = $details->description;
$gdas_event_type = $details->gdas:eventType;

}

trow the erro in this line "$gdas_event_type = $details-
>gdas:eventType;"


how can i parse this tag please nay one me to parse this feed ,
  Réponse avec citation
Vieux 17/06/2008, 09h48   #2
Tonio
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Parse the XML feed me

You can try :

$gdas_event_type = $details->{gdas:eventType};

not tested... but works for - in tag name.

Tonio

On Jun 17, 8:47am, Damodhar <damu...@gmail.com> wrote:
> Any one 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:eventType>EQ</gdas:eventType>
> <gdas:alertLevel>Green</gdas:alertLevel>
> <asgard:alertLevel>Green</asgard:alertLevel>
> <dc:subject>EQ_Green</dc:subject>
> </item>
> ================================================== =========
>
> my code :
> $xml = new SimpleXMLElement($xmldetails);
> foreach($content->item as $details)
> {
> $desaster_title = $details->title;
> $description = $details->description;
> $gdas_event_type = $details->gdas:eventType;
>
> }
>
> trow the erro in this line "$gdas_event_type = $details-
>
> >gdas:eventType;"

>
> how can i parse this tag please nay one me to parse this feed ,


  Réponse avec citation
Vieux 18/06/2008, 13h26   #3
David Gillen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Parse the XML feed me

On Tue, 17 Jun 2008 Damodhar <damu.be@gmail.com> wrote:
>
> Any one 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:eventType>EQ</gdas:eventType>
> <gdas:alertLevel>Green</gdas:alertLevel>
> <asgard:alertLevel>Green</asgard:alertLevel>
> <dc:subject>EQ_Green</dc:subject>
></item>
>================================================= ==========
>
> my code :
> $xml = new SimpleXMLElement($xmldetails);


do $xml = simplexml_load_string($xmldetails);
print_r($xml);
And it'll maybe 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.
  Réponse avec citation
Vieux 18/06/2008, 13h45   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Parse the XML feed me

On 18 Jun, 13:26, David Gillen <bel...@RedBrick.DCU.IE> wrote:
> On Tue, 17 Jun 2008 Damodhar <damu...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Any one 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:eventType>EQ</gdas:eventType>
> > <gdas:alertLevel>Green</gdas:alertLevel>
> > <asgard:alertLevel>Green</asgard:alertLevel>
> > <dc:subject>EQ_Green</dc:subject>
> ></item>
> >================================================= ==========

>
> > my code :
> > $xml = new SimpleXMLElement($xmldetails);

>
> do $xml = simplexml_load_string($xmldetails);
> print_r($xml);
> And it'll maybe 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.
  Réponse avec citation
Vieux 18/06/2008, 18h07   #5
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Parse the XML feed me

On Wed, 18 Jun 2008 14:45:27 +0200, Captain Paralytic
<paul_lautman@yahoo.com> wrote:

> On 18 Jun, 13:26, David Gillen <bel...@RedBrick.DCU.IE> wrote:
>> On Tue, 17 Jun 2008 Damodhar <damu...@gmail.com> wrote:
>>
>> > Any one 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:eventType>EQ</gdas:eventType>
>> > <gdas:alertLevel>Green</gdas:alertLevel>
>> > <asgard:alertLevel>Green</asgard:alertLevel>
>> > <dc:subject>EQ_Green</dc:subject>
>> ></item>
>> >================================================= ==========

>>
>> > my code :
>> > $xml = new SimpleXMLElement($xmldetails);

>>
>> do $xml = simplexml_load_string($xmldetails);
>> print_r($xml);
>> And it'll maybe 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:alertLevel>Green</gdas:alertLevel>
<asgard:alertLevel>Green</asgard:alertLevel>
<dc:subject>EQ_Green</dc:subject>
</item>";
libxml_use_internal_errors(true);
$xml = simplexml_load_string($string);
$errors = libxml_get_errors();
if(!empty($errors)){
foreach ($errors as $error) var_dump($error);
}
libxml_clear_errors();

//works:
var_dump($xml->eventType);
var_dump($xml->xpath('//eventType'));

//doesn't work as desired
var_dump($xml->{'gdas:eventType'});
var_dump($xml->xpath('//gdas:eventType'));

//check
echo $xml->asXML();
?>

Mind you, try to repeat that with:
$string = "<item xmlns='http://foobar' xmlns:gdas='http://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:alertLevel>Green</gdas:alertLevel>
<asgard:alertLevel>Green</asgard:alertLevel>
<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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h27.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18503 seconds with 13 queries