commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick_Hofst...@inventivedesigners.com
Subject Re: [JXPath] Namespace prefixes
Date Thu, 18 Mar 2004 09:28:16 GMT





Eternal fame and gratitude will be yours :)

Thank you,

Nick

"Dmitri Plotnikov" <dmitri@apache.org> wrote on 18/03/2004 06:11:23:

> I'll re-introduce the NamespaceManager in a couple of days.  I needed to
> collect more information as I did not quite understand the requirement. I
do
> now.  Thank you very much for your help.
>
> - Dmitri
>
> ----- Original Message -----
> From: <Nick_Hofstede@inventivedesigners.com>
> To: <commons-user@jakarta.apache.org>
> Sent: Wednesday, March 17, 2004 11:16 AM
> Subject: [JXPath] Namespace prefixes

> > Hi,
> >
> > I'm having the same problem as Sudhir a while ago.
> >
http://www.mail-archive.com/commons-user@jakarta.apache.org/msg05586.html
> >
> > He posted a good example that I'll repeat here:
> >
> >    I have a fairly simple xml document:
> >
> >    <?xml version="1.0"?>
> >    <bk:book xmlns:bk='urn:loc.gov:books'
> >    xmlns:isbn='urn:ISBN:0-395-36341-6'>
> >       <bk:title>Cheaper by the Dozen</bk:title>
> >       <isbn:number>1568491379</isbn:number>
> >    </bk:book>
> >
> >    To access say the isbn number I would use the following xpath in my
> >    code.
> >    /bk:book/isbn:number
> >
> >    Note that I need to specify the prefixes in my xpath or it won't
work.
> >
> >    Now if I had instead the following document which is identical for
all
> >    practical purposes with the earlier xml except that the prefixes are
> >    different, it is my opinion that my code still ought to work.
> >
> >    <?xml version="1.0"?>
> >    <ck:book xmlns:ck='urn:loc.gov:books'
> >    xmlns:idn='urn:ISBN:0-395-36341-6'>
> >       <ck:title>Cheaper by the Dozen</ck:title>
> >       <idn:number>1568491379</idn:number>
> >    </ck:book>
> >
> >    But it doesn't. And that is because the prefixes I am specifying in
my
> >    xpaths are not the same as what is used in the document.
> >
> > Dmitri implemented a NamespaceManager which would be a good solution to
> the
> > problem, but his patch got reversed.
> >
> > The problem remains however.
> >
> > Another less intrusive solution would be a setNamespace(String prefix,
> > String URI) function on a JXPathContext object.
> > This way all functionality that's present in Xalan is present in
JXPath.
> > As for XPaths on Java-objects, you could ignore all namespaces or
disallow
> > namespace qualifiers. I don't know what happens today if you specify a
> > namespace, but the behaviour could stay thesame.
> >
> > I'd very much like this namespace-prefix mapping feature to be
> > reconsidered, as currently JXPath isn't really usable for removing
silly
> > DOM-navigation-code when the Document uses namespaces.
> >
> > Nick Hofstede


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message