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 6321683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:11:38+00:00 2026-05-24T16:11:38+00:00

I fear that this is a really stupid question but I am really stuck

  • 0

I fear that this is a really stupid question but I am really stuck after trying a load of combinations for the last 2 hours. I am trying to pull the NAME out of the XML file

My XML file:

<?xml version="1.0"?>
<userdata>
<name>John</name>
</userdata>

My php:

  $doc          =  new DOMDocument();
  $doc          -> load( "thefile.xml" );
  $thename       =  $doc -> getElementsByTagName( "name" );
$myname= $thename -> getElementsByTagName("name") -> item(0) -> nodeValue;

The Error:

Catchable fatal error: Object of class DOMElement could not be converted to string in phpreader.php

I have tried

$myname= $thename -> getElementsByTagName("name") -> item(0) ;
$myname= $doc     -> getElementsByTagName("name") -> item(0) -> nodeValue;
$myname= $doc     -> getElementsByTagName("name") -> item(0) ;

but all fail. Guess I have tried just about every combination except the correct one 🙁

  • 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-24T16:11:39+00:00Added an answer on May 24, 2026 at 4:11 pm

    You may want $myname = $thename->item(0)->nodeValue. $thename is already the NodeList of all of the nodes whose tag is “name” – you want the first item of these (->item(0)), and you want the value of the node (->nodeValue). $thename should be more appropriately named $names, and you’d see why $names->item(0)->nodeValue makes sense semantically.

    This Works For MeTM.

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

Sidebar

Related Questions

I fear this is a really stupid question, but here goes: Why does the
I fear this may be a dumb question/easy fix, but have been stuck for
I fear this just may not be possible, but I'm trying to create a
This is really weird and I fear I have just done something dumb but
I want to develop a GAE application using python, but I fear that Google
I have read several questions regarding this but I fear they may be out
I fear this has been beaten to death, but I'm still struggling with the
this feels like a do my homework for me kind of question but I'm
I'm new to xslt, and I fear that this problem hinges on me getting
I fear I may be trying to do something that certain security policies are

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.