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

  • Home
  • SEARCH
  • 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 8274461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:44:17+00:00 2026-06-08T07:44:17+00:00

Consider the following XML: <s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/> <s:Body> <myResponse xmlns=https://example.com/foo> <myResult xmlns:a=https://example.com/bar xmlns:i=http://www.w3.org/2001/XMLSchema-instance> <a:accountNumber>AAA</a:accountNumber> <a:accountName>BBB</a:accountName>

  • 0

Consider the following XML:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <myResponse xmlns="https://example.com/foo">
         <myResult xmlns:a="https://example.com/bar" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:accountNumber>AAA</a:accountNumber>
            <a:accountName>BBB</a:accountName>
            <a:accountType>CCC</a:accountType>
         </myResult>
      </myResponse>
   </s:Body>
</s:Envelope>

I am attempting to select myResult and all the elements underneath it.

The closest I have gotten is:

//*[local-name()='myResult']//a:*

Which gets me the values of the elements, but I don’t know which which value belongs to which element.

I am doing this in PHP, here is (roughly) the code I am using:

<?php
$xmlObject = new SimpleXMLElement($result);
$namespaces = $xmlObject->getNamespaces(true);
foreach($namespaces as $key => $value) {
   if($key == '') {
      $key = 'ns';
   }
   $xmlObject->registerXPathNamespace($key, $value);
}
$element = $xmlObject->xpath("//myResult");
?>

I know there have been a bunch of questions about XPath and XML namespaces (Oh, how I’ve searched), but I haven’t found one that matches my particular case. Is what I want to do even possible?

  • 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-08T07:44:19+00:00Added an answer on June 8, 2026 at 7:44 am

    Your //*[local-name()='myResult']//a:* works fine. You just need to loop through and use getName to get the tag’s name.

    $element = $xmlObject->xpath("//*[local-name()='myResult']//a:*");
    foreach($element as $e){
        echo $e->getName() . ': '. (string)$e;
    }
    

    Demo: http://codepad.org/BAefIKZ4

    EDIT: Since you are registering the namespaces, why not use them?

    $element = $xmlObject->xpath("//ns:myResult//a:*");
    

    Demo: http://codepad.org/9MKq5oDt

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

Sidebar

Related Questions

For example, consider the following example <?xml version=1.0 ?> <rdf:RDF xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns# xmlns:dc=http://purl.org/dc/elements/1.1/> <rdf:Description rdf:about=http://en.wikipedia.org/wiki/Tony_Benn>
Consider the following radio button example. <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml> <mx:Script> <![CDATA[ private
Consider the following example: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html xmlns=http://www.w3.org/1999/xhtml
Let's consider the following XML Schema: <?xml version=1.0 encoding=UTF-8?> <schema targetNamespace=http://www.example.org/library elementFormDefault=qualified xmlns=http://www.w3.org/2001/XMLSchema xmlns:lib=http://www.example.org/library>
Consider the following XSLT script: <?xml version=1.0 encoding=ISO-8859-1?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output method=text encoding=iso-8859-1/>
consider my 'destinationURLLookUp.xml' file has the following structure <?xml version=1.0 encoding=UTF-8?> <destinationURLs xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <destinationURL
Consider the following: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en
Consider the following TSQL: declare @xml xml select @xml = '<test xmlns=http://this-is-the-default-namespace-uri>some data</test>' select
Consider following two examples: Example 1: <xs:import namespace=http://example.com/ns schemaLocation=test.xsd/> Example2: <sample:Data Test=true xsi:schemaLocation=http://example.com/test.xsd> How
Consider the following overly simplified chunk of XML: <ElementA> <AttributeValue DataType=http://www.w3.org/2001/XMLSchema#integer>5 </AttributeValue> </ElementA> Specifically,

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.