Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving single node value from a nodelist
    primarykey
    data
    text
    <p>I'm having difficulty extracting a single node value from a nodelist. </p> <p>My code takes an xml file which holds several fields, some containing text, file paths and full image names with extensions. </p> <p>I run an expath query over it, looking for the node item with a certain id. It then stores the matched node item and saves it as $oldnode</p> <p>Now my problem is trying to extract a value from that $oldnode. I have tried to var_dump($oldnode) and print_r($oldnode) but it returns the following: "object(DOMElement)#8 (0) { } "</p> <p>Im guessing the $oldnode variable is an object, but how do I access it?</p> <p>I am able to echo out the whole node list by using: echo $oldnode->nodeValue;</p> <p>This displays all the nodes in the list.</p> <p>Here is the code which handles the xml file. line 6 is the line in question... </p> <pre><code> $xpathexp = "//item[@id=". $updateID ."]"; $xpath = new DOMXpath($xml); $nodelist = $xpath-&gt;query($xpathexp); if((is_null($nodelist)) || (! is_numeric($nodelist))) { $oldnode = $nodelist-&gt;item(0); echo $oldnode-&gt;nodeValue; //$imgUpload = strchr($oldnode-&gt;nodeValue, ' '); //$imgUpload = strrchr($imgUpload, '/'); //explode('/',$imgUpload); //$imgUpload = trim($imgUpload); $newItem = new DomDocument; $item_node = $newItem -&gt;createElement('item'); //Create attribute on the node as well $item_node -&gt;setAttribute("id", $updateID); $largeImageText = $newItem-&gt;createElement('largeImgText'); $largeImageText-&gt;appendChild( $newItem-&gt;createCDATASection($largeImgText)); $item_node-&gt;appendChild($largeImageText); $urlANode = $newItem-&gt;createElement('urlA'); $urlANode-&gt;appendChild( $newItem-&gt;createCDATASection($urlA)); $item_node-&gt;appendChild($urlANode); $largeImg = $newItem-&gt;createElement('largeImg'); $largeImg-&gt;appendChild( $newItem-&gt;createCDATASection($imgUpload)); $item_node-&gt;appendChild($largeImg); $thumbnailTextNode = $newItem-&gt;createElement('thumbnailText'); $thumbnailTextNode-&gt;appendChild( $newItem-&gt;createCDATASection($thumbnailText)); $item_node-&gt;appendChild($thumbnailTextNode); $urlB = $newItem-&gt;createElement('urlB'); $urlB-&gt;appendChild( $newItem-&gt;createCDATASection($urlA)); $item_node-&gt;appendChild($urlB); $thumbnailImg = $newItem-&gt;createElement('thumbnailImg'); $thumbnailImg-&gt;appendChild( $newItem-&gt;createCDATASection(basename($_FILES['thumbnailImg']['name']))); $item_node-&gt;appendChild($thumbnailImg); $newItem-&gt;appendChild($item_node); $newnode = $xml-&gt;importNode($newItem-&gt;documentElement, true); // Replace $oldnode-&gt;parentNode-&gt;replaceChild($newnode, $oldnode); // Display $xml-&gt;save($xmlFileData); //header('Location: index.php?a=112&amp;amp;id=5'); </code></pre> <p>Any help would be great.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload