| | |
PHP XML DOM Get Childnodes and Attributes
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 36
Reputation:
Solved Threads: 0
I am trying to parse a XML document but can not seem to parse both Childnodes and Attributes in the same Foreach statement.
=====================
PHP CODE
=====================
Need the title childnode and all links from tag name "links" attribute "href" Thanks in Advance!
=====================
XML is from twitter
=====================
=====================
PHP CODE
=====================
PHP Syntax (Toggle Plain Text)
<?PHP $webResults = $response->getElementsByTagName($prnt0); if ($webResults->length<>0) { foreach($webResults as $value){ $title = $value->childNodes->item($child1)->nodeValue; } } ?>
Need the title childnode and all links from tag name "links" attribute "href" Thanks in Advance!
=====================
XML is from twitter
=====================
PHP Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="UTF-8"?> <feed xmlns:google="base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="a9.com/-/spec/opensearch/1.1/" xmlns="www.w3.org/2005/Atom" xmlns:twitter="api.twitter.com/"> <entry> <id>tag:search.twitter.com,2005:1982519510</id> <published>2009-05-31T18:22:20Z</published> <link type="text/html" rel="alternate" href="twitter.com/buildasearch/statuses/1982519510"/> <title>New Search Background Uploader ! Upload your favorite background image to BuildaSearch. GIF - JPEG - PNG. Just do it!</title> <content type="html">New Search Background Uploader ! Upload your favorite background image to <b>BuildaSearch</b>. GIF - JPEG - PNG. Just do it!</content> <updated>2009-05-31T18:22:20Z</updated> <link type="image/png" rel="image" href="amazonaws.com/twitter_production/profile_images/66983558/build_normal.png"/> <twitter:source><a href="twitter.com/">web</a></twitter:source> <twitter:lang>en</twitter:lang> <author> <name>buildasearch (buildasearch)</name> <uri>twitter.com/buildasearch</uri> </author> </entry> </feed>
Last edited by lonestar23; Jun 6th, 2009 at 7:59 pm. Reason: misspelling
Have you tried using a print_r( $webResults ); statement to make sure that this variable has the values you are hoping for?
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
So the issue is above the decleration of $webResults, whats $prnt0 ?
It seems like the method you are using to fetch the data is not working.
It seems like the method you are using to fetch the data is not working.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
•
•
Join Date: Mar 2008
Posts: 36
Reputation:
Solved Threads: 0
$prnt0 equals 'entry'
Let me know if the new code is detailed enough. I know how to get the attributes using SimpleXML and DOM, but can not frigure out how to get childnodes and attribute information at the same time using DOM.
Thanks,
PHP Syntax (Toggle Plain Text)
<?PHP $gurl = 'search.twitter.com/search.atom?lang=en&q=devo' $getUrl = $gurl; $resUrl = new DOMDocument(); $resUrl->load($getUrl); $prnt0 = 'entry'; $webResults = $resUrl->getElementsByTagName($prnt0); if ($webResults->length<>0) { foreach($webResults as $value){ $title = $value->childNodes->item($child1)->nodeValue; } } ?>
Let me know if the new code is detailed enough. I know how to get the attributes using SimpleXML and DOM, but can not frigure out how to get childnodes and attribute information at the same time using DOM.
Thanks,
This seems to be your issue
Try
You need to do this for pretty much every variable you have so as you know were things are dropping their values.
Maybe take a look at either the manual or the documentation about this specific method as I don't have much knowledge of it.
Could you not create a function that uses a series of explotions and loops to extract the values?
I could give you some help with this. I am not really much of a PHP 5 & 6 guy as I learnt PHP years ago. PHP 5 should suffice.
$webResults = $resUrl->getElementsByTagName($prnt0); .Try
print_r( $resUrl ); this should print out something.You need to do this for pretty much every variable you have so as you know were things are dropping their values.
Maybe take a look at either the manual or the documentation about this specific method as I don't have much knowledge of it.
Could you not create a function that uses a series of explotions and loops to extract the values?
I could give you some help with this. I am not really much of a PHP 5 & 6 guy as I learnt PHP years ago. PHP 5 should suffice.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
@Josh, PHP 6 doesn't exist yet and wont for a long while 
For lonestar. getElementsByTagName returns a DOMNodeList which, when iterated over, each entry is a DOMNode which can act as a DOMElement which has the function getAttribute($attr_name); So you can do (in theory, see php.net/DOM):
}

For lonestar. getElementsByTagName returns a DOMNodeList which, when iterated over, each entry is a DOMNode which can act as a DOMElement which has the function getAttribute($attr_name); So you can do (in theory, see php.net/DOM):
php Syntax (Toggle Plain Text)
$elemlist = $someDom->getElementsByTagName('link'); foreach($elemlist as $elem) { var_dump($elem); }
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Oh I am in my own little world, don't mind me
.
I haven't taken much of a look at PHP5. Not sure if it is the version but the shit with all of the arrows, make my neck crawl. It seems pointless.
.I haven't taken much of a look at PHP5. Not sure if it is the version but the shit with all of the arrows, make my neck crawl. It seems pointless.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
That "shit with all of the arrows" is OOP, you'll pretty much have to learn it to work on any PHP newer than version 4. Do a few google searches on imperative vs object oriented programming and you'll have your answer to whether or not it's pointless
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- Problems with browser compatibility.. especially internet explorer (JavaScript / DHTML / AJAX)
- Need help with PHP site and IE - Operation Aborted (PHP)
- Help No output??? php noob (PHP)
- to select a string from textarea (JavaScript / DHTML / AJAX)
- Choppy when Scrolling Down (Viruses, Spyware and other Nasties)
- Inserting dynamic values into Javascript variables (JavaScript / DHTML / AJAX)
- return a value to php form (PHP)
- JavaScript/DHTML newbie -- general questions (JavaScript / DHTML / AJAX)
- Please check this LOG ... Sys32 window opens on startup (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Need Help : Failed to connect to mailserver
- Next Thread: make directory
Views: 2087 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






