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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:17:33+00:00 2026-05-25T15:17:33+00:00

I am looking into the use of xpath from within Javascript. I have an

  • 0

I am looking into the use of xpath from within Javascript.

I have an XMLHttpRequest(), which retrieves a KML document. KML is just a particular flavor of XML.

I get the document via xhr.responseXML, the result looks like this:

<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="1">
      <IconStyle>
        <color>7f66CC33</color>
        <Icon>
          <href />
        </Icon>
      </IconStyle>
       ...
    </Style>
    <Folder>
      ....
    </Folder>
  </Document>
</kml>

Then I want to perform queries on it to select nodes.

    xmlDom.setProperty("SelectionLanguage", "XPath");
    xmlDom.setProperty("SelectionNamespaces","xmlns='http://www.opengis.net/kml/2.2'");
    nodeList = xmlDom.selectNodes("/kml/Document/Folder");

But this isn’t working for me. I expect to get at least one node, but I get zero.

Q1: Can anyone explain why this is not working?

As I was looking into this, I discovered to my surprise that xpath is not supported in XML Documents in the browser, in a cross-browser fashion. Apparently the selectNodes() function is an IE-only thing?

Q2: Can anyone confirm this?

If this is true, then what should I be doing for cross-browser node selection from an XML document, from within the browser.

Q3: How do I do cross-browser XPath queries, on an XML document?


ps: I specifically don’t care about doing “xpath on html”. It’s an XML document I’m querying.

  • 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-25T15:17:33+00:00Added an answer on May 25, 2026 at 3:17 pm

    You have:

    xmlDom.setProperty("SelectionLanguage", "XPath"); 
    xmlDom.setProperty("SelectionNamespaces","xmlns='http://www.opengis.net/kml/2.2'"); 
    nodeList = xmlDom.selectNodes("/kml/Document/Folder"); 
    

    Must be:

    xmlDom.setProperty("SelectionLanguage", "XPath"); 
    xmlDom.setProperty("SelectionNamespaces","xmlns:x='http://www.opengis.net/kml/2.2'"); 
    nodeList = xmlDom.selectNodes("/x:kml/x:Document/x:Folder"); 
    

    Explanation:

    Any unprefixed name in an XPath expression in considered to beling to “no namespace”.

    Therefore, the expression:

    /kml/Document/Folder
    

    attempts to select elements named Folder that are in “no namespace” but in the provided documents all elementa are in the default (non-null) http://www.opengis.net/kml/2.2 namespace and there is no element in “no namespace”. This is why the XPath expression above can’t select any element.

    The solution is to register a namespace binding of a non-empty prefix to the default namespace and most importantly, use this prefix to prefix any name in the XPath expression.

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

Sidebar

Related Questions

I have recently started looking into Google Charts API for possible use within the
I'm looking into the possibilities of creating a Javascript application which makes use webGL.
I have been looking into javascript wysiwyg text editors for use on a topicality
I have been looking into IKVMing Apache's FOP project to use with our .NET
I was just going to use the FileUpload.FileBytes property but looking into the respective
I use Tortoise SVN usuallly, but I have been looking into Mercurial since it
I just started looking into the use of jQuery UI. What I would like
I have been looking into different types of timers that i could use for
I've been looking into the use of the Unicode 'N' constant within my code,
I have just started looking into using Modules in Flex and would like to

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.