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

adamc at unc.edu adamc at unc.edu
Thu Dec 6 19:47:29 EST 2007


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?




More information about the XOM-interest mailing list