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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:00:35+00:00 2026-06-07T00:00:35+00:00

I’m trying to run some xpath queries on some XML that contains namespaces. Unfortunately

  • 0

I’m trying to run some xpath queries on some XML that contains namespaces. Unfortunately it’s giving me a rather horrid error message as it does not understand the namespaces in the xpath query or the XML.

A sample xpath query is: //b:menuBarItem[@label='Risk']/@id

Can I configure the namespaces in JOOX (1.1.0), in a similar fashion to how I’ve done it here using the built in java library?

  private static NamespaceContext createXPathNameSpaceContext( final Map<String, String> namespaces ) {
    NamespaceContext nsContext = new NamespaceContext() {
      public Iterator<String> getPrefixes( String namespaceURI ) {
        return null;
      }
      public String getPrefix( String namespaceURI ) {
        return null;
      }
      public String getNamespaceURI( String prefix ) {
        if ( namespaces.containsKey( prefix ) ) {
          return namespaces.get( prefix );
        } else {
          return XMLConstants.NULL_NS_URI;
        }
      }
    };
    return nsContext;
  }

I’m invoking JOOX with the following code.

import static org.joox.JOOX.$;

private void extractResponseData( Document responseXML, String xpath ) {
  String match = $( responseXML ).xpath( xpath ).get( 0 ).getNodeValue();
  // .. etc..
}

The obvious thing that stands out is that I have not registered the namespaces, but I couldn’t see how to. I suspect I am being rather short-sighted and have overlooked something in the API. The stack trace I am getting from JOOX is the following.

java.lang.RuntimeException: javax.xml.xpath.XPathExpressionException
    at org.joox.Impl.xpath(Impl.java:494)
    at org.joox.Impl.xpath(Impl.java:467)
    at org.joox.Impl.xpath(Impl.java:93)
    at end2end.http.HttpAction$XML.extractResponseData(HttpAction.java:181)
    at end2end.http.XMLPostAction.extractResponseData(XMLPostAction.java:26)
    at end2end.http.HttpAction.perform(HttpAction.java:58)
    at end2end.TestXML$UserAction.fire(TestXML.java:176)
    at end2end.TestXML$FireAction.fire(TestXML.java:148)
    at end2end.TestXML.multipleUsers(TestXML.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:336)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:65)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:88)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:215)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: javax.xml.xpath.XPathExpressionException
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:402)
    at org.joox.Impl.xpath(Impl.java:486)
    at org.joox.Impl.xpath(Impl.java:467)
    at org.joox.Impl.xpath(Impl.java:93)
    at end2end.http.HttpAction$XML.extractResponseData(HttpAction.java:181)
    at end2end.http.XMLPostAction.extractResponseData(XMLPostAction.java:27)
    at end2end.http.HttpAction.perform(HttpAction.java:58)
    at end2end.TestXML$UserAction.fire(TestXML.java:176)
    at end2end.TestXML$FireAction.fire(TestXML.java:148)
    at end2end.TestXML.multipleUsers(TestXML.java:120)
    ... 24 more
Caused by: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: 
    at com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:653)
    at com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:638)
    at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:265)
    at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:96)
    at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:110)
    at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:176)
    at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:264)
    at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:394)
    at org.joox.Impl.xpath(Impl.java:486)
    at org.joox.Impl.xpath(Impl.java:467)
    at org.joox.Impl.xpath(Impl.java:93)
    at end2end.http.HttpAction$XML.extractResponseData(HttpAction.java:181)
    at end2end.http.XMLPostAction.extractResponseData(XMLPostAction.java:26)
    at end2end.http.HttpAction.perform(HttpAction.java:58)
    at end2end.TestXML$UserAction.fire(TestXML.java:176)
    at end2end.TestXML$FireAction.fire(TestXML.java:148)
    at end2end.TestXML.multipleUsers(TestXML.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    ... 1 more
  • 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-07T00:00:38+00:00Added an answer on June 7, 2026 at 12:00 am

    jOOX doesn’t support XML namespaces (yet). There is a pending feature request regarding this topic here:

    http://code.google.com/p/joox/issues/detail?id=9

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.