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
=====================

<?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
=====================

<?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 &lt;b&gt;BuildaSearch&lt;/b&gt;.  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>&lt;a href="twitter.com/"&gt;web&lt;/a&gt;</twitter:source>
    <twitter:lang>en</twitter:lang>
    <author>
      <name>buildasearch (buildasearch)</name>
      <uri>twitter.com/buildasearch</uri>
    </author>
  </entry>
</feed>

Have you tried using a print_r( $webResults ); statement to make sure that this variable has the values you are hoping for?

I got the following running print_r($webResults);

"DOMNodeList Object ()" and that is all....

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.

$prnt0 equals 'entry'

<?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 $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.

@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):

$elemlist = $someDom->getElementsByTagName('link');
foreach($elemlist as $elem) {
  var_dump($elem);
}

}

Oh I am in my own little world, don't mind me :P.

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.

Oh I am in my own little world, don't mind me :P.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.