[jdom-interest] Two namespace-questions (revisited)
Michael Kay
mike at saxonica.com
Wed Jun 6 08:03:07 PDT 2007
If you don't like the XPath 1.0 specification, why not try XPath 2.0?
XPath 2.0 allows you to set a default namespace for unqualified names in
path expressions, and you can use that against JDOM input if you use Saxon.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: jdom-interest-bounces at jdom.org
> [mailto:jdom-interest-bounces at jdom.org] On Behalf Of Kai Wörner
> Sent: 06 June 2007 15:36
> To: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Two namespace-questions (revisited)
>
> Hello again,
>
> I'm stumbling over this same problem again and again! Now I'd
> like to simply show parts of the same input XML file as last
> time inside a Java program based on an XPath-expression. I
> simply provide an input field for the XPath-string and seeing
> the problems that the users already have drafting a
> XPath-expression, I simply _know_ that they'll fail if they
> have to add a namespace-declaration before each and every
> element-name they use (especially since they don't have to do
> this in any of the XML-Editors they use).
> In addition, if I use an XMLOutputter to output the matched
> Elements, they come out with another load of namespace-bulk
> none of my users will understand. So in my tool I'd have to
> use an expression like:
>
> //tei:s
>
> to get a result that looks like that:
>
> <s xmlns="http://www.tei-c.org/ns/1.0" part="N" TEIform="s">
> <cl type="lMAI tDEC" part="N" TEIform="cl">
>
> as opposed to any XML-Editor where I'd use:
>
> //s
>
> to get:
>
> <s>
> <cl type="lMAI tDEC">
>
> Is it possible /at all/ to mimic the way it works in a
> XML-Editor at all in JDom or do I have to look someplace else?
>
> Thanks again,
>
> Kai
>
>
> XML: http://files.exmaralda.org/bl.xml
>
>
>
>
>
> > There is no default namespace in XPath 1.0.
> > So you have to use a namespace prefix in your XPath
> expressions. You
> > can choose any prefix as there is no relationship between
> the prefixes
> > used in XPath and the ones in the document: prefixes are just
> > shortcuts and the matching is done on the actual namespace URIs.
> >
> > The following should work:
> > XPath xp = XPath.newInstance("/x:*");
> > xp.addNamespace("x", "http://www.tei-c.org/ns/1.0");
> > xp.selectNodes(document);
> >
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@you
> rhost.com
More information about the jdom-interest
mailing list