christopherpm Posted October 8, 2006 Share Posted October 8, 2006 I have an XML/RSS feed that I want to extract some data from, and I really don't know how....I can get most bits of data out of the feed, but my problem lies with these two issues:-<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>- <rss version="2.0" xmlns:abouttown="there is a URL here">- <channel> <title>My title</title> <description>My description</description> <abouttown:location city="A City Name" country="UK" />- <image> <title>Image Title</title> </image>- <item> <title>Item Title</title> </item> ............ 1) How do I extract the city and country from the above to display in my HTML document?2) There is a Channel tag, and Image tag and an Item tag (in that order) - within each of these there is a Title tag - I want to get the Title tag from Item. How do I get that?I would appreciate any help (and apologise if this seems like a stupid question).Thank you. Link to comment Share on other sites More sharing options...
boen_robot Posted October 8, 2006 Share Posted October 8, 2006 What language will you be using to get the data? What do you have at your disposal? JavaScript only? Or is there a server side scripting language too? If there is, what is it? PHP, ASP.NET, Cold Fusion, JSP...?By the way, your document isn't a valid RSS document, though it is a well-formed XML one. Link to comment Share on other sites More sharing options...
christopherpm Posted October 8, 2006 Author Share Posted October 8, 2006 I use PHP... Link to comment Share on other sites More sharing options...
christopherpm Posted October 11, 2006 Author Share Posted October 11, 2006 From what I have gathered so far, I assume I have to use getElementsByTagNameNS but I still cannot get the result I want which is to show the value of "city" from abouttown:locationAny ideas? Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2006 Share Posted October 11, 2006 You may simply use some of the XML functions. Either Expath, DOM or simple XML.Scince Simple XML is... well... simple, here's a sample of what might work for you: <?php$xml = simplexml_load_file("test.xml");$result = $xml->xpath("/rss/channel/abouttown:location/@city");print_r($result);?> Link to comment Share on other sites More sharing options...
christopherpm Posted October 11, 2006 Author Share Posted October 11, 2006 It's getting close, but in the example above, using my actual xml file, I get the following result:-Array ( [0] => SimpleXMLElement Object ( [0] => Fort William ) ) The actual city name is "Fort William", and it is just that text that I want to display - can the other text be stripped off?ALSO, my web host is using PHP 4.4.4 not 5.x - is this available in a pre-V5.x PHP? Link to comment Share on other sites More sharing options...
boen_robot Posted October 11, 2006 Share Posted October 11, 2006 I'm not that experienced with PHP.What I can tell you is that the actual result you see is a multidimensional array with the results you want. If the query had returned a number of elements, each element's content would have been in a different key from the array. The problem is I don't know how to deal with multidimensional arrays.Yes, Simple XML is available in PHP5 by default too, and scince this worked for your PHP4 host, I guess it works there too. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now