TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   XML, XSLT, XPath, XQuery (http://www.talkphp.com/xml-xslt-xpath-xquery/)
-   -   XML help! How to get elements from an xml (http://www.talkphp.com/xml-xslt-xpath-xquery/4056-xml-help-how-get-elements-xml.html)

ezia 03-18-2009 08:54 PM

XML help! How to get elements from an xml
 
Hey, I was wondering how you get certain elements from an xml file.

Say I had

Code:

<title>Hello!</title>

<body>Woop Woop</title>

<footer>Hey there</footer>

How could I just get the <title>Hello</title> From this xml file?

Salathe 03-18-2009 09:53 PM

That's not an XML file (more precisely, it's invalid XML) but a good place to start would be to read the PHP manual pages on SimpleXML

Wildhoney 07-30-2009 04:20 PM

I've started to get more into XPath recently, and it is a fantastic way to traverse the nodes! Something like so:

Code:

//span[@class='time']/parent::div
That would select all the span elements where the class is precisely time -- if it's not precise you can use the contains function. Then its parent node of type div.

It's such a beautiful way of doing things!

Salathe 07-30-2009 05:34 PM

I would go so far as to call it beautiful but XPath is very useful indeed.

P.S. Why on earth is that a reply to this topic?

Wildhoney 07-31-2009 12:34 AM

As this particular forum is dead! :-( And... and... XPath is useful for this kind of stuff.


All times are GMT. The time now is 02:41 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0