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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:04:56+00:00 2026-06-03T09:04:56+00:00

I have the following XML: http://pastebin.com/QiRK72BK which is generated in response to a REST

  • 0

I have the following XML: http://pastebin.com/QiRK72BK

which is generated in response to a REST query. My code is very simple:

$xml = simplexml_load_file($url);

var_dump($xml->getName());

var_dump($xml->xpath("serverDetail/apiEnv"));

in an attempted test case. The first var_dump reveals that the XML file is indeed being loaded:

 string(21) "GeneralSearchResponse"

However, the second var_dump puzzles me. I feel it should definitely match some data, but instead I get

array(0) { }

I’ve also tried the xpath “/serverDetail/apiEnv” “//apiEnv” and “/” and always get an empty array. Am I misunderstanding xpath or perhaps missing some initialization step?

  • 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-03T09:04:58+00:00Added an answer on June 3, 2026 at 9:04 am

    Your XML is using a namespace:

    $xml->registerXPathNamespace('u', 'urn:types.partner.api.shopping.com');
    var_dump($xml->xpath("//u:serverDetail/u:apiEnv"));
    

    Output:

    array(1) {
      [0]=>
      object(SimpleXMLElement)#2 (1) {
        [0]=>
        string(7) "sandbox"
      }
    }
    

    Edit: Dirty workaround, might be helpful though:

    $xml = simplexml_load_file($url);
    $xmlStr = str_replace("xmlns", "ns", $xml->asXML());
    $xml = new SimpleXMLElement($xmlStr);
    var_dump($xml->xpath("serverDetail/apiEnv"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: $page=3; $i=1; while($i<=$pages) { $urls .= '.http://twitter.com/favorites.xml?page= . $i
I have the following XML: <ns:response xmlns:ns=http://example.com xmlns:ax=http://example.com/xsd > <ns:return type=mytype> <ax:roleID>1</ax:roleID> <ax:roleName>ADM</ax:roleName> </ns:return>
I have the following xml I need to read the values of: <po-response xmlns=http://test.com<
I have the following xml data: <portfolio> <item> <title>Site</title> <description>Site.com is a </description> <url>http://www.site.com</url>
I have the following XML document: <places xmlns=http://where.yahooapis.com/v1/schema.rng xmlns:yahoo=http://www.yahooapis.com/v1/base.rng yahoo:start=0 yahoo:count=1 yahoo:total=1> <place yahoo:uri=http://where.yahooapis.com/v1/place/23424975
I have the following XML which I am trying to query with XDocument: <E2ETraceEvent
I have the following XML example: <?xml version=1.0 encoding=UTF-8?> <OpenSearchDescription xmlns=http://a9.com/-/spec/opensearch/1.1/ xmlns:custom=http://example.com/opensearchextensions/1.0/> <ShortName>Test</ShortName> <Description>Testing....</Description>
I have the following xml object representing a ImageButton <?xml version=1.0 encoding=utf-8?> <ImageButton xmlns:android=http://schemas.android.com/apk/res/android
I have the following XML: <?xml version=1.0?> <?xml-stylesheet type=text/xsl href=http://www.test.com/AuditTrail.xsl?> and XSL: <?xml version=1.0
I have the following Xml in my Resources.xmltest: <?xml version=1.0 encoding=utf-8 ?> <Response xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

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.