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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:12:29+00:00 2026-06-17T06:12:29+00:00

I have below XML which contains a default namespace <?xml version=1.0?> <catalog xmlns=http://www.edankert.com/examples/> <cd>

  • 0

I have below XML which contains a default namespace

<?xml version="1.0"?>
<catalog xmlns="http://www.edankert.com/examples/">
  <cd>
    <artist>Stoat</artist>
    <title>Future come and get me</title>
  </cd>
  <cd>
    <artist>Sufjan Stevens</artist>
    <title>Illinois</title>
  </cd>
  <cd>
    <artist>The White Stripes</artist>
    <title>Get behind me satan</title>
  </cd>
</catalog>

And Im running following code expecting some result in return

Element rootElem = new Builder().build(xml).getRootElement();
xc = XPathContext.makeNamespaceContext(rootElem);
xc.addNamespace("", "http://www.edankert.com/examples/");   
Nodes matchedNodes = rootElem.query("cd/artist", xc);
System.out.println(matchedNodes.size());

But the size is always 0.

I gone through

  • https://stackoverflow.com/a/9674145/1160106 [I really didnt get the weired xpath syntax]
  • http://www.edankert.com/defaultnamespaces.html#Jaxen_and_XOM [Can see some hope. Just requires a major change in my current implementation]

Looking forward for any help.

  • 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-17T06:12:31+00:00Added an answer on June 17, 2026 at 6:12 am

    Unprefixed names in XPath always mean “no namespace” – they don’t respect the default namespace declaration. You need to use a prefix

    Element rootElem = new Builder().build(xml).getRootElement();
    xc = XPathContext.makeNamespaceContext(rootElem);
    xc.addNamespace("ex", "http://www.edankert.com/examples/");   
    Nodes matchedNodes = rootElem.query("ex:cd/ex:artist", xc);
    System.out.println(matchedNodes.size());
    

    It doesn’t matter that the XPath expression uses a prefix where the original document didn’t, as long as the namespace URI that is bound to the prefix in the XPath namespace context is the same as the URI that is bound by xmlns in the document.

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

Sidebar

Related Questions

<?xml version=1.0?> <configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0> <configSections> I have a web.config file which contains xmlns in
I have XML shaped like the following: <?xml version=1.0 encoding=UTF-8?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http://a9.com/-/spec/opensearch/1.1/ xmlns:docs=http://schemas.google.com/docs/2007
I have a XML file which contains a part like below. img and br
I have an application which contains the line below to assign a parsed XML
I have an XML file which contains lists of stores, a simplified version is
I have a XML file which contains the below section: <cptasks> <copy file=file1.txt to=folder1/folder21
Below is my design: <html xml:lang=en xmlns=http://www.w3.org/1999/xhtml lang=en> <head> </head> <body> <div id=wrapper> <div
I have a bit of xml file named Sample.xml which is shown below <?xml
I have an XML file which has many section like the one below: <Operations>
I have a sample xml file which looks like the one below: <Root> <SubOne>

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.