TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-18-2009, 08:54 PM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
ezia is on a distinguished road
Default 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?
ezia is offline  
Reply With Quote
Old 03-18-2009, 09:53 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

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
Salathe is offline  
Reply With Quote
Old 07-30-2009, 04:20 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

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!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 07-30-2009, 05:34 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
Salathe is on a distinguished road
Default

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?
Salathe is offline  
Reply With Quote
Old 07-31-2009, 12:34 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,267
Thanks: 90
Wildhoney is on a distinguished road
Default

As this particular forum is dead! And... and... XPath is useful for this kind of stuff.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Jquery Accordion limit of elements? sarmenhb Javascript, AJAX, E4X 4 02-02-2009 11:27 AM
floating list elements sarmenhb XHTML, HTML, CSS 4 09-20-2008 11:19 AM
adjacent selectors should allow for different elements delayedinsanity XHTML, HTML, CSS 5 07-13-2008 08:21 PM
array elements into variables and values Dave Absolute Beginners 7 06-20-2008 01:56 PM
Xhtml 2.0 Wildhoney XHTML, HTML, CSS 3 09-11-2007 02:55 PM


All times are GMT. The time now is 11:20 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design