Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1104085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:26:07+00:00 2026-05-17T01:26:07+00:00

I’m having difficulty extracting a single node value from a nodelist. My code takes

  • 0

I’m having difficulty extracting a single node value from a nodelist.

My code takes an xml file which holds several fields, some containing text, file paths and full image names with extensions.

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

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) { } “

Im guessing the $oldnode variable is an object, but how do I access it?

I am able to echo out the whole node list by using: echo $oldnode->nodeValue;

This displays all the nodes in the list.

Here is the code which handles the xml file. line 6 is the line in question…

 $xpathexp = "//item[@id=". $updateID ."]";
            $xpath = new DOMXpath($xml);
            $nodelist = $xpath->query($xpathexp);
            if((is_null($nodelist)) || (! is_numeric($nodelist))) {
              $oldnode = $nodelist->item(0);
              echo $oldnode->nodeValue;
              //$imgUpload = strchr($oldnode->nodeValue, ' ');
              //$imgUpload = strrchr($imgUpload, '/');
              //explode('/',$imgUpload);

              //$imgUpload = trim($imgUpload); 


              $newItem = new DomDocument;
              $item_node = $newItem ->createElement('item');

               //Create attribute on the node as well
              $item_node ->setAttribute("id", $updateID);

              $largeImageText = $newItem->createElement('largeImgText');
              $largeImageText->appendChild( $newItem->createCDATASection($largeImgText));
              $item_node->appendChild($largeImageText);

              $urlANode = $newItem->createElement('urlA');
              $urlANode->appendChild( $newItem->createCDATASection($urlA));
              $item_node->appendChild($urlANode);

              $largeImg = $newItem->createElement('largeImg');
              $largeImg->appendChild( $newItem->createCDATASection($imgUpload));
              $item_node->appendChild($largeImg);

              $thumbnailTextNode = $newItem->createElement('thumbnailText');
              $thumbnailTextNode->appendChild( $newItem->createCDATASection($thumbnailText));
              $item_node->appendChild($thumbnailTextNode);

              $urlB = $newItem->createElement('urlB');
              $urlB->appendChild( $newItem->createCDATASection($urlA));
              $item_node->appendChild($urlB);

              $thumbnailImg = $newItem->createElement('thumbnailImg');
              $thumbnailImg->appendChild( $newItem->createCDATASection(basename($_FILES['thumbnailImg']['name'])));
              $item_node->appendChild($thumbnailImg);

              $newItem->appendChild($item_node);

              $newnode = $xml->importNode($newItem->documentElement, true);

                       // Replace
              $oldnode->parentNode->replaceChild($newnode, $oldnode);

              // Display
              $xml->save($xmlFileData);
                               //header('Location: index.php?a=112&id=5');

Any help would be great.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:26:08+00:00Added an answer on May 17, 2026 at 1:26 am

    Wasn’t it supposed to be echo $oldnode->firstChild->nodeValue;? I remember this because technically you need the value from the text node.. but I might be mistaken, it’s been a while. You could give it a try?

    After our discussion in the comments on this answer, I came up with this solution. I’m not sure if it can be done cleaner, perhaps. But it should work.

    $nodelist = $xpath->query($xpathexp);
    if((is_null($nodelist)) || (! is_numeric($nodelist))) {
        $oldnode = $nodelist->item(0);
    
        $largeImg       = null;
        $thumbnailImg   = null;
        foreach( $oldnode->childNodes as $node ) {
            if( $node->nodeName == "largeImg" ) {
                $largeImg       = $node->nodeValue;
            } else if( $node->nodeName == "thumbnailImg" ) {
                $thumbnailImg   = $node->nodeValue;
            }
        }
    
        var_dump($largeImg);
        var_dump($thumbnailImg);
    }
    

    You could also use getElementsByTagName on the $oldnode, then see if it found anything (and if a node was found, $oldnode->getElementsByTagName(“thumbnailImg”)->item(0)->nodeValue). Which might be cleaner then looping through them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.