Re: Two namespace-questions (revisited)

"Kai Wörner" <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
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/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.