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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:45:46+00:00 2026-06-10T19:45:46+00:00

I am working with PHP and XPath connecting to a remote XML based API.

  • 0

I am working with PHP and XPath connecting to a remote XML based API. A sample response from the server is as this one below.

    <OTA_PingRS>
        <Success />
        <EchoData>This is some test data</EchoData>
    </OTA_PingRS>

You can see there is no starting tag <Success> so how do I search for the existance of <Success /> using Xpath?

Thanks
Simon

  • 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-06-10T19:45:47+00:00Added an answer on June 10, 2026 at 7:45 pm

    The <Success /> element is an empty element, meaning it has no value. It is both, Start and End Tag.

    You can test for existence of nodes with the XPath function boolean()

    The boolean function converts its argument to a boolean as follows:

    • a number is true if and only if it is neither positive or negative zero nor NaN
    • a node-set is true if and only if it is non-empty
    • a string is true if and only if its length is non-zero
    • an object of a type other than the four basic types is converted to a boolean in a way that is dependent on that type

    To do that with DOMXPath you need to use the DOMXPath::evaluate() method because it will return a typed result, in this case a boolean:

    $xml = <<< XML
    <OTA_PingRS>
        <Success />
        <EchoData>This is some test data</EchoData>
    </OTA_PingRS>
    XML;
    
    $dom = new DOMDocument;
    $dom->loadXml($xml);
    
    $xpath = new DOMXPath($dom);
    $successNodeExists = $xpath->evaluate('boolean(/OTA_PingRS/Success)');
    
    var_dump($successNodeExists); // true
    

    demo


    Of course, you can also just query for /OTA_PingRS/Success and see whether there are results in the returned DOMNodeList:

    $xml = <<< XML
    <OTA_PingRS>
        <Success />
        <EchoData>This is some test data</EchoData>
    </OTA_PingRS>
    XML;
    
    $dom = new DOMDocument;
    $dom->loadXml($xml);
    
    $xpath = new DOMXPath($dom);
    $successNodeList = $xpath->evaluate('/OTA_PingRS/Success');
    
    var_dump($successNodeList->length);
    

    demo


    You can also use SimpleXML:

    $xml = <<< XML
    <OTA_PingRS>
        <Success />
        <EchoData>This is some test data</EchoData>
    </OTA_PingRS>
    XML;
    
    $nodeCount = count(simplexml_load_string($xml)->xpath('/OTA_PingRS/Success'));
    
    var_dump($nodeCount); // 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on PHP project that should fetch emails from IMAP server, and
Working with PHP Xpath trying to quickly pull certain links within a html page.
We currently have a working php mail script, this works fine and as we
Need to xpath xml data based on greater than date attribute. The dashes in
I have a simple working PHP script to write an HTML table from a
I have a working PHP server. Now I want to use databases (MySQL or
HI i have a working php based pagination which works fine, but when i
While working with PHP ,handling connection's with Database (MySQL) $result = mysql_query('select * from
How? More to the point... this: $url = 'http://php.net/manual/en/class.domelement.php'; $client = new Zend_Http_Client($url); $response
I am extracting data from a forum. My script based on is working fine.

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.