Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] XOM Unknown namespace prefix : Noob Question

xom-interest AT

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: adamc AT
  • To: xom-interest AT
  • Subject: Re: [XOM-interest] XOM Unknown namespace prefix : Noob Question
  • Date: Thu, 06 Dec 2007 19:47:29 -0500

Quoting Bhaskar Maddala <maddalab AT>:

The key here is that namespaces are actually identified by URIs (the prefix is more or less there for convenience). The namepsace spec is quite short, and worth reading:

In the case of XOM's XPath support, what you need to do is "bind" the URI to a prefix of your choosing via an instance of the nu.xom.XPathContext class, which you then pass in to the query() method:

XPathContext ctx = new XPathContext("myprefix", "";);
Nodes nodes = document.query("myprefix:BusinessObjects/myprefix:RequestSettings", ctx);




From my limited understanding I do not believe the client is restricted in
using any namespace prefix when creating a xml that conforms to the schema
definition above.

Here is an example of the xml I receive for processing

<?xml version="1.0" encoding="UTF-8"?>
<ns1:BusinessObjects xmlns:ns1="";>

I use the following code to retrieve a nu.xom.Document instance

Builder builder = new Builder();
StringReader reader = new StringReader(request);
Document document =;

When I attempt to do the following
Nodes nodes = m_document.query("BusinessObjects/RequestSettings");

nodes.size() is zero. I think this is because XPath is Namespace aware
and I need the prefix ns1 in the query XPath expression.

Question : Currently I do not know the prefix used by the client making
the request, is there any way in XOM for me to retrieve the prefix so that I
can use it elsewhere, or better yet is there an option that would allow the
existing query to work?

Archive powered by MHonArc 2.6.24.

Top of Page