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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:35:27+00:00 2026-05-16T15:35:27+00:00

I have this simplexml result object: object(SimpleXMLElement)#207 (2) { [@attributes]=> array(1) { [version]=> string(1)

  • 0

I have this simplexml result object:

 object(SimpleXMLElement)#207 (2) {
  ["@attributes"]=>
  array(1) {
   ["version"]=>
   string(1) "1"
  }
  ["weather"]=>
  object(SimpleXMLElement)#206 (2) {
   ["@attributes"]=>
   array(1) {
   ["section"]=>
   string(1) "0"
  }
  ["problem_cause"]=>
  object(SimpleXMLElement)#94 (1) {
   ["@attributes"]=>
   array(1) {
   ["data"]=>
   string(0) ""
   }
  }
  }
 }

I need to check if the node “problem_cause” exists. Even if it is empty, the result is an error.
On the php manual, I found this php code that I modified for my needs:

 function xml_child_exists($xml, $childpath)
 {
    $result = $xml->xpath($childpath);
    if (count($result)) {
        return true;
    } else {
        return false;
    }
 }

 if(xml_child_exists($xml, 'THE_PATH')) //error
 {
  return false;
 }
 return $xml;

I have no idea what to put in place of the xpath query ‘THE_PATH’ to check if the node exists.
Or is it better to convert the simplexml object to dom?

  • 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-16T15:35:27+00:00Added an answer on May 16, 2026 at 3:35 pm

    Sounds like a simple isset() solves this problem.

    <?php
    $s = new SimpleXMLElement('<foo version="1">
      <weather section="0" />
      <problem_cause data="" />
    </foo>');
    // var_dump($s) produces the same output as in the question, except for the object id numbers.
    echo isset($s->problem_cause)  ? '+' : '-';
    
    $s = new SimpleXMLElement('<foo version="1">
      <weather section="0" />
    </foo>');
    echo isset($s->problem_cause)  ? '+' : '-';
    

    prints +- without any error/warning message.

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

Sidebar

Related Questions

I have this SimpleXML object: object(SimpleXMLElement)#176 (1) { [record]=> array(2) { [0]=> object(SimpleXMLElement)#39 (2)
I have this object parsed using SimpleXML: SimpleXMLElement Object ( [contact] => SimpleXMLElement Object
I have a foreach loop which loops through an array (simpleXML nodes). This array
I have this simplexml object and it looks fine, but when i convert a
I am using simpleXML and get back the result like so: SimpleXMLElement Object (
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have a SimpleXML element, from XML like the following: <Result> <BlueAnswer>Blue</BlueAnswer> <RedAnswer>Red</RedAnswer> <YellowAnswer>Yellow</YellowAnswer>
i have problem with simpleXml and adding new items. This is my xml: <?xml
I have a multi-dimensional multi-object array from a simplexml_import_dom() function call. A slice of

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.