473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:alertLeve l>Green</gdas:alertLevel >
<asgard:alertLe vel>Green</asgard:alertLev el>
<dc:subject>EQ_ Green</dc:subject>
</item>
=============== =============== =============== ==============

my code :
$xml = new SimpleXMLElemen t($xmldetails);
foreach($conten t->item as $details)
{
$desaster_title = $details->title;
$description = $details->description;
$gdas_event_typ e = $details->gdas:eventType ;

}

trow the erro in this line "$gdas_event_ty pe = $details-
>gdas:eventType ;"
how can i parse this tag please nay one help me to parse this feed ,
Jun 27 '08 #1
4 1485
You can try :

$gdas_event_typ e = $details->{gdas:eventTyp e};

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: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);
foreach($conten t->item as $details)
{
* *$desaster_titl e *= * * $details->title;
* *$description * *= * * *$details->description;
* *$gdas_event_ty pe * * = * * * $details->gdas:eventType ;

}

trow the erro in this line "$gdas_event_ty pe * * * = * * * $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:alertLeve l>Green</gdas:alertLevel >
<asgard:alertLe vel>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.
Jun 27 '08 #3
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.
Jun 27 '08 #4
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
Jun 27 '08 #5

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

Similar topics

15
5194
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
1999
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> <link>http://www.websiteurl.com</link> <description>Description of website</description> <lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate> <docs>http://backend.userland.com/rss092</docs>
5
2104
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 domain and directory is left over. Expected result:
8
7425
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 (text/html) for this document is used to serve both SGML and XML based documents, and it is not possible to disambiguate it based on the DOCTYPE Declaration in your document. Parsing will continue in SGML mode."...
8
5039
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 see below from excel, word, notepad, etc.. into a textbox on my form. I need to break each line into 2 numbers which I'll use as parameters for another function. in all cases each line will be separated with a vbNewline and in most cases the 2...
1
2119
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 = curl_init("http://feddsitegoeshere"); curl_setopt($feed, CURLOPT_RETURNTRANSFER, 1); $p= curl_exec($feed); curl_close();
5
64652
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
1
64206
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
5
2710
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 what the fix is. Thanks.
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7547
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.