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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:28:28+00:00 2026-06-05T23:28:28+00:00

I have an xml string such as this: <s:Envelope xmlns:s=http://schemas.xmlsoap.org/soap/envelope/> <s:Body> <ExecuteResponse xmlns=http://schemas.microsoft.com/xrm/2011/Contracts/Services> <ExecuteResult

  • 0

I have an xml string such as this:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
      <ExecuteResult i:type="a:RetrieveEntityResponse" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:ResponseName>RetrieveEntity</a:ResponseName>
        <a:Results xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <b:key>Some Value</b:key>
          </a:KeyValuePairOfstringanyType>
        </a:Results>
      </ExecuteResult>
    </ExecuteResponse>
  </s:Body>
</s:Envelope>

I’m trying to do something along the lines of:

var resolver = xmlDoc.createNSResolver(xmlDoc.documentElement);
return new XPathEvaluator().evaluate("//b:key", xmlDoc.documentElement, resolver, XPathResult.ANY_TYPE, null);

The key node is not being found, and the reason is when I call

resolver.lookupNamespaceURI("b")

directly, it returns null. However, it does return something when I do

resolver.lookupNamespaceURI("s")

so my best guess is the createNSResolver method only looks for namespaces in the root node of the xml document that is passed in. Is there any way to make it find all of the namespaces that are defined in the xml, or some other way to build a list of all of the namespaces that exist in the document?

Thanks!

  • 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-05T23:28:30+00:00Added an answer on June 5, 2026 at 11:28 pm

    Well setting up consistent namespace resolving based on all namespace declarations in the XML document is not possible in the general case as you could have e.g.

    <root xmlns="http://example.com/n1">
      <foo xmlns="http://example.com/n2">
       <p1:bar xmlns:p1="http://example.com/n1">
        <p2:baz xmlns:p2="http://example.com/n1">...</p2:baz>
       </p1:bar>
      </foo>
    </root>
    

    where the same namespace is used with different prefixes and of course you could have samples as e.g.

    <p:foo xmlns:p="http://example.com/n1">
      <p:bar xmlns:p="http://example.com/n2">...</p:bar>
    </p:foo>
    

    where the same prefix is bound to different namespace URIs on different elements.

    So basically you need to know the namespace URI of the element node you are looking for, then you can set up a namespace resolver with any prefix your code can choose e.g.

    return xmlDoc.evaluate("//pf:key", xmlDoc, function(prefix) { if (prefix === 'pf' return 'http://schemas.datacontract.org/2004/07/System.Collections.Generic'; else return null; }, XPathResult.ANY_TYPE, null);
    

    On the other hand with that simple path I would not use XPath and evaluate at all but rather go for return xmlDoc.getElementsByTagNameNS('http://schemas.datacontract.org/2004/07/System.Collections.Generic', 'b');.

    As for finding namespace declarations in a DOM tree to build up a namespace resolver yourself based on prefixes, XPath can give some assistance itself by looking at the namespace axis e.g. //namespace::* but inside the browser Mozilla/Firefox never considered it necessary to support the namespace axis. Then there are some DOM Level 3 methods http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespacePrefix and http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-lookupNamespaceURI so you could write your own code walking the DOM tree and collecting namespace declarations but that does not help in the general case to solve the problems outlined in the two example samples I posted above.

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

Sidebar

Related Questions

I have an XML string like <Segment xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:type=Air> <carrier /> ... </Segment> I
I have an Xml document: <?xml version=1.0 encoding=utf-8?> <Family xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Person member=father id=0>
I have the following XML: <?xml version=1.0?> <coll xmlns=http://www.example.org/coll xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.example.org/coll coll.xsd> <collection> <item
I have an XML (in BizTalk) that looks like <ns0:Provide xmlns:ns0=http1 xmlns:ns1=http2 xmlns:ns2=http://schemas.microsoft.com/2003/10/Serialization/> <ns0:providerRequest>
I have a xml string: <Test> Result : this is the result</Test> How do
I'm trying to turn this XML string into a select I have @Schedule XML
Suppose I have this XML as a string: <calles> <calle> <nombre>CALLAO AV.</nombre> <altura>1500</altura> <longitud>-58.3918617027</longitud>
I need to parse XML string into an array. I have XML <group xmlns=123
I have written a soap/web service that returns a string such as: <GeocodeResponse><City>Denver</City><State>CO</State></GeocodeResponse> I
This is what I have in my schema.xml: <fields> <field name=id type=string indexed=true stored=true

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.