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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:07:42+00:00 2026-05-19T05:07:42+00:00

I have a simple XML document <abc:MyForm xmlns:abc=’http://myform.com’> <abc:Forms> <def:Form1 xmlns:def=’http://decform.com’> …. </def:Form1> <ghi:Form2

  • 0

I have a simple XML document

<abc:MyForm xmlns:abc='http://myform.com'>
    <abc:Forms>
        <def:Form1 xmlns:def='http://decform.com'>
            ....
        </def:Form1>
        <ghi:Form2 xmlns:ghi='http://ghiform.com'>
            ....
        </ghi:Form2>
    </abc:Forms>
</abc:MyForm>

I’m using XMLObjects from Apache and when I try to do the following xpath expression it works perfectly

object.selectPath("declare namespace abc='http://myform.com' 
                   abc:Form/abc:Forms/*");

this gives me the 2 Form nodes (def and ghi). However I want to be able to query by specifying a namespace, so let’s say I only want Form2. I’ve tried this and it fails

object.selectPath("declare namespace abc='http://myform.com' 
                   abc:Form/abc:Forms/*
                      [namespace-uri() = 'http://ghiform.com']");

The selectPath returns 0 nodes. Does anyone know what is going on?

Update:

If I do the following in 2 steps, then I can get the result that I want.

 XmlObject forms = object.selectPath("declare namespace abc='http://myform.com' 
                   abc:Form/abc:Forms")[0];
 forms.selectPath("*[namespace-uri() = 'http://ghiform.com']");

this gives me the ghi:Form node just like it should, I don’t understand why it doesn’t do it as a single XPath expression though.
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-05-19T05:07:42+00:00Added an answer on May 19, 2026 at 5:07 am

    The simple answer is that you can’t. The namespace prefix is just a shorthand for the namespace URI, which is all that matters.

    For a namespace-aware parser, your two tags are identical.

    If you really want to differentiate using the prefix (although you really, really shouldn’t be doing it), you can use a non namespace-aware parser and just treat the prefix as if it was part of the element name.

    But ideally you should read a tutorial on how namespaces work and try to use them as they were designed to be used.

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

Sidebar

Related Questions

I have a simple xml document that looks like the following snippet. I need
Situation: I have a simple XML document that contains image information. I need to
I have a simple xml node inside an xml document in C# that I
I have a very simple XML document that I've retrieved from a larger parent.
I have a simple question about Java's XML API and I hope there's a
I have an rss XML file: <?xml version=1.0 encoding=UTF-8?> <rss version=2.0> <channel> <title>ABC News</title>
I have this code, loading XML documents on mouseenter, which works in Firefox: $(document).ready(function()
I have a simple doc.xml file which contains a single root element with a
Consider this simple XML document. The serialized XML shown here is the result of
I have an XML document, want to do syntax highlighting. The code uses XPathDocument

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.