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

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using the function encodeURIComponent over your text value. It,… May 17, 2026 at 2:24 am
  • Editorial Team
    Editorial Team added an answer Bit late but I was looking for this as well… May 17, 2026 at 2:24 am
  • Editorial Team
    Editorial Team added an answer This website says you can only build basic import and… May 17, 2026 at 2:24 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a multi-dimensional multi-object array from a simplexml_import_dom() function call. A slice of
i have problem with simpleXml and adding new items. This is my xml: <?xml
I have an XML feed that looks like this: <?xml version=1.0 encoding=UTF-8?> <productFeed version=1.0
This is my RSS template that I load into my simplexml object. I want
I'm using simpleXML to parse this xml file . It's a feed I'm using
Consider this simple XML document. The serialized XML shown here is the result of
I have this code: $reader = new DOMDocument(); $reader->loadHTML($shell); $xpath = new DomXPath($reader); $xpath->registerNamespace('html','http://www.w3.org/1999/xhtml');
This is starting to piss me off real bad. I have this XML code:
Simple one guys. I have an XML parsed using simplexml_load_file(). The following code: <?php
I have a very simple XML: <Rows> <Row> <id>1</id> <name>foo</name> <more>xyz</more> </Row> <Row> <id>2</id>

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.