Skip to Content.
Sympa Menu

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

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

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

Quoting Bhaskar Maddala <maddalab AT gmail.com>:

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: http://www.w3.org/TR/REC-xml-names/

In the case of XOM's XPath support, what you need to do is "bind" the URI http://schemas.mycompany.com/2007/pro 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", "http://schemas.mycompany.com/2007/pro";);
Nodes nodes = document.query("myprefix:BusinessObjects/myprefix:RequestSettings", ctx);

HTH

AC

Hello,

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="http://schemas.mycompany.com/2007/pro";>
<ns1:RequestSettings>
....
</ns1:RequestSettings>
</ns1:BusinessObjects>

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

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

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