473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Parse the XML feed help me


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: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 help me to parse this feed ,
Jun 27 '08 #1
4 1465
You can try :

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

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

Tonio

On Jun 17, 8:47*am, 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: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 help me to parse this feed ,
Jun 27 '08 #2
On Tue, 17 Jun 2008 Damodhar <da*****@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: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 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.
Jun 27 '08 #3
On 18 Jun, 13:26, David Gillen <bel...@RedBrick.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: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 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.
Jun 27 '08 #4
On Wed, 18 Jun 2008 14:45:27 +0200, Captain Paralytic
<pa**********@yahoo.comwrote:
On 18 Jun, 13:26, David Gillen <bel...@RedBrick.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: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 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: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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
2
by: Charles Stricklin | last post by:
If I have an RSS newsfeed like this: <?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" --> <rss version="0.92"> <channel> <title>Website Name</title>...
5
by: Andreas Volz | last post by:
Hi, I used SGMLParser to parse all href's in a html file. Now I need to cut some strings. For example: http://www.example.com/dir/example.html Now I like to cut the string, so that only...
8
by: Spartanicus | last post by:
The document at http://homepage.ntlworld.com/spartanicus/custom_dtd.htm uses a custom DTD, the w3c validator validates it but with this warning: "Unknown Parse Mode! The MIME Media Type...
8
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
1
by: Paul | last post by:
alllow_url_fopen if set to off. For some reason I can not access domxml_open_file(). And I need to read an xml feed. I can access the feed using cURL: $feed =...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
5
by: goldtech | last post by:
SAX XML Parse Python error message Hi, My first attempt at SAX, but have an error message I need help with. I cite the error message, code, and xml below. Be grateful if anyone can tell me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.