You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Dmitri Plotnikov <dm...@apache.org> on 2004/01/18 02:52:47 UTC
Re: [JXPath] Registering namespace prefixes
Chap,
I added registration of external namespaces to JXPath. My solution is a
little different from the one proposed by Sudhir. The main difference in
the API is that instead of calling registerNamespace directly on
JXPathContext, you call it indirectly like this:
JXPathContext context = JXPathContext.newContext(document);
NamespaceManager nsm = context.getNamespaceManager();
nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
Take a look at the NamespaceManager interface - you can supply your own
implementation, which could perform very flexible customizations of
namespace lookup.
Please note that external namespaces are supported with DOM but not JDOM,
because JDOM B9 at this point requires that all namespaces be explicitly
declared in the XML file itself.
Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
they address your needs, I will highly appreciate it.
Thanks,
- Dmitri
----- Original Message -----
From: "Sudhir Rao" <su...@att.net>
To: <ch...@hotmail.com>
Cc: <co...@jakarta.apache.org>
Sent: Saturday, December 06, 2003 6:41 PM
Subject: Re: [JXPath] Registering namespace prefixes
> I made some local modifications for this. I am not sure if adding that
> registerNamespace is the right way to do it, as I am not very familiar
> with the codebase. The changes I did locally were to
> a) Modify org.apache.commons.jxpath.ri.QName.java to include the
> namespace prefix (similar to the one in Apache Axis). Had to tweak it a
> bit to consider the prefix as the namespaceURI however to keep it
> compatible with existing code.
> b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
> class.
> c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
> the QName instance returned.
> d) Add the registerNamespace method to JXPathContextReferenceImpl and
> JXPathContext which in turn call a registerNamespace in Compiler class.
>
> I can send across my changes if someone would like to look into it.
>
> -Sudhir
>
> >From: Prasad A. Chodavarapu <ch...@hotmail.com>
> >Subject: [JXPath] Registering namespace prefixes
> >Date: Wed, 3 Dec 2003 12:32:23 -0500
> >Content-Type: text/plain;
> > charset="iso-8859-1"
> >
> >
> >
> >Hi All:
> >
> >Is there a way of registering a namespace prefix upfront in a
> >JXPathContext so that I can then use that prefix in xpath expressions?
> >Here's what I'm looking for, in pseudo-code.
> >
> >JXPathContext domContext = JXPathContext.newContext(document);
> >domContext.registerNamespace
> > (http://www.example.com/ns/sample, "prefix");
> >domContext.getValue("prefix:a/prefix:b");
> >
> >Thanks
> >chap
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Dmitri Plotnikov <dm...@apache.org>.
I understand now. Let me read a little more before I reintroduce this
feature.
In XPath 2 there is this notion of in-scope-namespaces. Are these two
related?
- Dmitri
----- Original Message -----
From: "Sudhir Rao" <su...@att.net>
To: "Dmitri Plotnikov" <dm...@apache.org>
Cc: <ch...@hotmail.com>; "Jakarta Commons Developers List"
<co...@jakarta.apache.org>; "Jakarta Commons Users List"
<co...@jakarta.apache.org>
Sent: Tuesday, January 20, 2004 5:45 PM
Subject: Re: [JXPath] Registering namespace prefixes - never mind
> Dmitri,
>
> I was looking at it mainly for xml documents. I am not sure how
> this maps out to Java objects (and as I mentioned earlier as I don't
> have a very good idea in that respect). Here is what I feel the issue is
> with xml documents (Chap pointed this out briefly earlier).
> 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"?>
> <!-- both namespace prefixes are available throughout -->
> <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. I need the
> xpaths being used to stay consistent and I ought to be able to specify
> the namespace mappings. So that when I say "I want to access the xpath
> /||bk:book/isbn:number", I can specify exactly what I mean by bk and
> isbn in this xpath.
>
> There might be a easier, cleaner way using jxpath, but I am not
> aware of it at this point. If you could specify alternatives that would
> be great. For my purposes I think Xalan might be a better fit for now.
>
> Regards
> Sudhir
> ||
>
> |
> Dmitri Plotnikov wrote:
>
> >Chap, Sudhir,
> >
> >After some profound discussions on the jdom-interest@jdom.org mailing
list,
> >I decided to roll back this new feature. I need to better understand the
> >use case before I introduce this new API.
> >
> >Is the functionality you are referring to intended for use with Java
> >objects? What is the meaning of a namespace URI in the context of Java
> >objects? Please, give me as much information about this use case as
> >possible.
> >
> >- Dmiri
> >
> >----- Original Message -----
> >From: "Dmitri Plotnikov" <dm...@apache.org>
> >To: <ch...@hotmail.com>; "Jakarta Commons Users List"
> ><co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
> >Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> >Sent: Saturday, January 17, 2004 8:52 PM
> >Subject: Re: [JXPath] Registering namespace prefixes
> >
> >
> >
> >
> >>Chap,
> >>
> >>I added registration of external namespaces to JXPath. My solution is a
> >>little different from the one proposed by Sudhir. The main difference
in
> >>the API is that instead of calling registerNamespace directly on
> >>JXPathContext, you call it indirectly like this:
> >>
> >> JXPathContext context = JXPathContext.newContext(document);
> >> NamespaceManager nsm = context.getNamespaceManager();
> >> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
> >>
> >>Take a look at the NamespaceManager interface - you can supply your own
> >>implementation, which could perform very flexible customizations of
> >>namespace lookup.
> >>
> >>Please note that external namespaces are supported with DOM but not
JDOM,
> >>because JDOM B9 at this point requires that all namespaces be explicitly
> >>declared in the XML file itself.
> >>
> >>Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
> >>they address your needs, I will highly appreciate it.
> >>
> >>Thanks,
> >>
> >>- Dmitri
> >>
> >>
> >>----- Original Message -----
> >>From: "Sudhir Rao" <su...@att.net>
> >>To: <ch...@hotmail.com>
> >>Cc: <co...@jakarta.apache.org>
> >>Sent: Saturday, December 06, 2003 6:41 PM
> >>Subject: Re: [JXPath] Registering namespace prefixes
> >>
> >>
> >>
> >>
> >>>I made some local modifications for this. I am not sure if adding that
> >>>registerNamespace is the right way to do it, as I am not very familiar
> >>>with the codebase. The changes I did locally were to
> >>>a) Modify org.apache.commons.jxpath.ri.QName.java to include the
> >>>namespace prefix (similar to the one in Apache Axis). Had to tweak it a
> >>>bit to consider the prefix as the namespaceURI however to keep it
> >>>compatible with existing code.
> >>>b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
> >>>class.
> >>>c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
> >>>the QName instance returned.
> >>>d) Add the registerNamespace method to JXPathContextReferenceImpl and
> >>>JXPathContext which in turn call a registerNamespace in Compiler class.
> >>>
> >>>I can send across my changes if someone would like to look into it.
> >>>
> >>>-Sudhir
> >>>
> >>>
> >>>
> >>>>From: Prasad A. Chodavarapu <ch...@hotmail.com>
> >>>>Subject: [JXPath] Registering namespace prefixes
> >>>>Date: Wed, 3 Dec 2003 12:32:23 -0500
> >>>>Content-Type: text/plain;
> >>>>charset="iso-8859-1"
> >>>>
> >>>>
> >>>>
> >>>>Hi All:
> >>>>
> >>>>Is there a way of registering a namespace prefix upfront in a
> >>>>JXPathContext so that I can then use that prefix in xpath expressions?
> >>>>Here's what I'm looking for, in pseudo-code.
> >>>>
> >>>>JXPathContext domContext = JXPathContext.newContext(document);
> >>>>domContext.registerNamespace
> >>>> (http://www.example.com/ns/sample, "prefix");
> >>>>domContext.getValue("prefix:a/prefix:b");
> >>>>
> >>>>Thanks
> >>>>chap
> >>>>
> >>>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Dmitri Plotnikov <dm...@apache.org>.
I understand now. Let me read a little more before I reintroduce this
feature.
In XPath 2 there is this notion of in-scope-namespaces. Are these two
related?
- Dmitri
----- Original Message -----
From: "Sudhir Rao" <su...@att.net>
To: "Dmitri Plotnikov" <dm...@apache.org>
Cc: <ch...@hotmail.com>; "Jakarta Commons Developers List"
<co...@jakarta.apache.org>; "Jakarta Commons Users List"
<co...@jakarta.apache.org>
Sent: Tuesday, January 20, 2004 5:45 PM
Subject: Re: [JXPath] Registering namespace prefixes - never mind
> Dmitri,
>
> I was looking at it mainly for xml documents. I am not sure how
> this maps out to Java objects (and as I mentioned earlier as I don't
> have a very good idea in that respect). Here is what I feel the issue is
> with xml documents (Chap pointed this out briefly earlier).
> 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"?>
> <!-- both namespace prefixes are available throughout -->
> <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. I need the
> xpaths being used to stay consistent and I ought to be able to specify
> the namespace mappings. So that when I say "I want to access the xpath
> /||bk:book/isbn:number", I can specify exactly what I mean by bk and
> isbn in this xpath.
>
> There might be a easier, cleaner way using jxpath, but I am not
> aware of it at this point. If you could specify alternatives that would
> be great. For my purposes I think Xalan might be a better fit for now.
>
> Regards
> Sudhir
> ||
>
> |
> Dmitri Plotnikov wrote:
>
> >Chap, Sudhir,
> >
> >After some profound discussions on the jdom-interest@jdom.org mailing
list,
> >I decided to roll back this new feature. I need to better understand the
> >use case before I introduce this new API.
> >
> >Is the functionality you are referring to intended for use with Java
> >objects? What is the meaning of a namespace URI in the context of Java
> >objects? Please, give me as much information about this use case as
> >possible.
> >
> >- Dmiri
> >
> >----- Original Message -----
> >From: "Dmitri Plotnikov" <dm...@apache.org>
> >To: <ch...@hotmail.com>; "Jakarta Commons Users List"
> ><co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
> >Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
> >Sent: Saturday, January 17, 2004 8:52 PM
> >Subject: Re: [JXPath] Registering namespace prefixes
> >
> >
> >
> >
> >>Chap,
> >>
> >>I added registration of external namespaces to JXPath. My solution is a
> >>little different from the one proposed by Sudhir. The main difference
in
> >>the API is that instead of calling registerNamespace directly on
> >>JXPathContext, you call it indirectly like this:
> >>
> >> JXPathContext context = JXPathContext.newContext(document);
> >> NamespaceManager nsm = context.getNamespaceManager();
> >> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
> >>
> >>Take a look at the NamespaceManager interface - you can supply your own
> >>implementation, which could perform very flexible customizations of
> >>namespace lookup.
> >>
> >>Please note that external namespaces are supported with DOM but not
JDOM,
> >>because JDOM B9 at this point requires that all namespaces be explicitly
> >>declared in the XML file itself.
> >>
> >>Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
> >>they address your needs, I will highly appreciate it.
> >>
> >>Thanks,
> >>
> >>- Dmitri
> >>
> >>
> >>----- Original Message -----
> >>From: "Sudhir Rao" <su...@att.net>
> >>To: <ch...@hotmail.com>
> >>Cc: <co...@jakarta.apache.org>
> >>Sent: Saturday, December 06, 2003 6:41 PM
> >>Subject: Re: [JXPath] Registering namespace prefixes
> >>
> >>
> >>
> >>
> >>>I made some local modifications for this. I am not sure if adding that
> >>>registerNamespace is the right way to do it, as I am not very familiar
> >>>with the codebase. The changes I did locally were to
> >>>a) Modify org.apache.commons.jxpath.ri.QName.java to include the
> >>>namespace prefix (similar to the one in Apache Axis). Had to tweak it a
> >>>bit to consider the prefix as the namespaceURI however to keep it
> >>>compatible with existing code.
> >>>b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
> >>>class.
> >>>c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
> >>>the QName instance returned.
> >>>d) Add the registerNamespace method to JXPathContextReferenceImpl and
> >>>JXPathContext which in turn call a registerNamespace in Compiler class.
> >>>
> >>>I can send across my changes if someone would like to look into it.
> >>>
> >>>-Sudhir
> >>>
> >>>
> >>>
> >>>>From: Prasad A. Chodavarapu <ch...@hotmail.com>
> >>>>Subject: [JXPath] Registering namespace prefixes
> >>>>Date: Wed, 3 Dec 2003 12:32:23 -0500
> >>>>Content-Type: text/plain;
> >>>>charset="iso-8859-1"
> >>>>
> >>>>
> >>>>
> >>>>Hi All:
> >>>>
> >>>>Is there a way of registering a namespace prefix upfront in a
> >>>>JXPathContext so that I can then use that prefix in xpath expressions?
> >>>>Here's what I'm looking for, in pseudo-code.
> >>>>
> >>>>JXPathContext domContext = JXPathContext.newContext(document);
> >>>>domContext.registerNamespace
> >>>> (http://www.example.com/ns/sample, "prefix");
> >>>>domContext.getValue("prefix:a/prefix:b");
> >>>>
> >>>>Thanks
> >>>>chap
> >>>>
> >>>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
> >
> >
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Sudhir Rao <su...@att.net>.
Dmitri,
I was looking at it mainly for xml documents. I am not sure how
this maps out to Java objects (and as I mentioned earlier as I don't
have a very good idea in that respect). Here is what I feel the issue is
with xml documents (Chap pointed this out briefly earlier).
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"?>
<!-- both namespace prefixes are available throughout -->
<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. I need the
xpaths being used to stay consistent and I ought to be able to specify
the namespace mappings. So that when I say "I want to access the xpath
/||bk:book/isbn:number", I can specify exactly what I mean by bk and
isbn in this xpath.
There might be a easier, cleaner way using jxpath, but I am not
aware of it at this point. If you could specify alternatives that would
be great. For my purposes I think Xalan might be a better fit for now.
Regards
Sudhir
||
|
Dmitri Plotnikov wrote:
>Chap, Sudhir,
>
>After some profound discussions on the jdom-interest@jdom.org mailing list,
>I decided to roll back this new feature. I need to better understand the
>use case before I introduce this new API.
>
>Is the functionality you are referring to intended for use with Java
>objects? What is the meaning of a namespace URI in the context of Java
>objects? Please, give me as much information about this use case as
>possible.
>
>- Dmiri
>
>----- Original Message -----
>From: "Dmitri Plotnikov" <dm...@apache.org>
>To: <ch...@hotmail.com>; "Jakarta Commons Users List"
><co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
>Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
>Sent: Saturday, January 17, 2004 8:52 PM
>Subject: Re: [JXPath] Registering namespace prefixes
>
>
>
>
>>Chap,
>>
>>I added registration of external namespaces to JXPath. My solution is a
>>little different from the one proposed by Sudhir. The main difference in
>>the API is that instead of calling registerNamespace directly on
>>JXPathContext, you call it indirectly like this:
>>
>> JXPathContext context = JXPathContext.newContext(document);
>> NamespaceManager nsm = context.getNamespaceManager();
>> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
>>
>>Take a look at the NamespaceManager interface - you can supply your own
>>implementation, which could perform very flexible customizations of
>>namespace lookup.
>>
>>Please note that external namespaces are supported with DOM but not JDOM,
>>because JDOM B9 at this point requires that all namespaces be explicitly
>>declared in the XML file itself.
>>
>>Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
>>they address your needs, I will highly appreciate it.
>>
>>Thanks,
>>
>>- Dmitri
>>
>>
>>----- Original Message -----
>>From: "Sudhir Rao" <su...@att.net>
>>To: <ch...@hotmail.com>
>>Cc: <co...@jakarta.apache.org>
>>Sent: Saturday, December 06, 2003 6:41 PM
>>Subject: Re: [JXPath] Registering namespace prefixes
>>
>>
>>
>>
>>>I made some local modifications for this. I am not sure if adding that
>>>registerNamespace is the right way to do it, as I am not very familiar
>>>with the codebase. The changes I did locally were to
>>>a) Modify org.apache.commons.jxpath.ri.QName.java to include the
>>>namespace prefix (similar to the one in Apache Axis). Had to tweak it a
>>>bit to consider the prefix as the namespaceURI however to keep it
>>>compatible with existing code.
>>>b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
>>>class.
>>>c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
>>>the QName instance returned.
>>>d) Add the registerNamespace method to JXPathContextReferenceImpl and
>>>JXPathContext which in turn call a registerNamespace in Compiler class.
>>>
>>>I can send across my changes if someone would like to look into it.
>>>
>>>-Sudhir
>>>
>>>
>>>
>>>>From: Prasad A. Chodavarapu <ch...@hotmail.com>
>>>>Subject: [JXPath] Registering namespace prefixes
>>>>Date: Wed, 3 Dec 2003 12:32:23 -0500
>>>>Content-Type: text/plain;
>>>>charset="iso-8859-1"
>>>>
>>>>
>>>>
>>>>Hi All:
>>>>
>>>>Is there a way of registering a namespace prefix upfront in a
>>>>JXPathContext so that I can then use that prefix in xpath expressions?
>>>>Here's what I'm looking for, in pseudo-code.
>>>>
>>>>JXPathContext domContext = JXPathContext.newContext(document);
>>>>domContext.registerNamespace
>>>> (http://www.example.com/ns/sample, "prefix");
>>>>domContext.getValue("prefix:a/prefix:b");
>>>>
>>>>Thanks
>>>>chap
>>>>
>>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>>
>>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Sudhir Rao <su...@att.net>.
Dmitri,
I was looking at it mainly for xml documents. I am not sure how
this maps out to Java objects (and as I mentioned earlier as I don't
have a very good idea in that respect). Here is what I feel the issue is
with xml documents (Chap pointed this out briefly earlier).
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"?>
<!-- both namespace prefixes are available throughout -->
<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. I need the
xpaths being used to stay consistent and I ought to be able to specify
the namespace mappings. So that when I say "I want to access the xpath
/||bk:book/isbn:number", I can specify exactly what I mean by bk and
isbn in this xpath.
There might be a easier, cleaner way using jxpath, but I am not
aware of it at this point. If you could specify alternatives that would
be great. For my purposes I think Xalan might be a better fit for now.
Regards
Sudhir
||
|
Dmitri Plotnikov wrote:
>Chap, Sudhir,
>
>After some profound discussions on the jdom-interest@jdom.org mailing list,
>I decided to roll back this new feature. I need to better understand the
>use case before I introduce this new API.
>
>Is the functionality you are referring to intended for use with Java
>objects? What is the meaning of a namespace URI in the context of Java
>objects? Please, give me as much information about this use case as
>possible.
>
>- Dmiri
>
>----- Original Message -----
>From: "Dmitri Plotnikov" <dm...@apache.org>
>To: <ch...@hotmail.com>; "Jakarta Commons Users List"
><co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
>Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
>Sent: Saturday, January 17, 2004 8:52 PM
>Subject: Re: [JXPath] Registering namespace prefixes
>
>
>
>
>>Chap,
>>
>>I added registration of external namespaces to JXPath. My solution is a
>>little different from the one proposed by Sudhir. The main difference in
>>the API is that instead of calling registerNamespace directly on
>>JXPathContext, you call it indirectly like this:
>>
>> JXPathContext context = JXPathContext.newContext(document);
>> NamespaceManager nsm = context.getNamespaceManager();
>> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
>>
>>Take a look at the NamespaceManager interface - you can supply your own
>>implementation, which could perform very flexible customizations of
>>namespace lookup.
>>
>>Please note that external namespaces are supported with DOM but not JDOM,
>>because JDOM B9 at this point requires that all namespaces be explicitly
>>declared in the XML file itself.
>>
>>Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
>>they address your needs, I will highly appreciate it.
>>
>>Thanks,
>>
>>- Dmitri
>>
>>
>>----- Original Message -----
>>From: "Sudhir Rao" <su...@att.net>
>>To: <ch...@hotmail.com>
>>Cc: <co...@jakarta.apache.org>
>>Sent: Saturday, December 06, 2003 6:41 PM
>>Subject: Re: [JXPath] Registering namespace prefixes
>>
>>
>>
>>
>>>I made some local modifications for this. I am not sure if adding that
>>>registerNamespace is the right way to do it, as I am not very familiar
>>>with the codebase. The changes I did locally were to
>>>a) Modify org.apache.commons.jxpath.ri.QName.java to include the
>>>namespace prefix (similar to the one in Apache Axis). Had to tweak it a
>>>bit to consider the prefix as the namespaceURI however to keep it
>>>compatible with existing code.
>>>b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
>>>class.
>>>c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
>>>the QName instance returned.
>>>d) Add the registerNamespace method to JXPathContextReferenceImpl and
>>>JXPathContext which in turn call a registerNamespace in Compiler class.
>>>
>>>I can send across my changes if someone would like to look into it.
>>>
>>>-Sudhir
>>>
>>>
>>>
>>>>From: Prasad A. Chodavarapu <ch...@hotmail.com>
>>>>Subject: [JXPath] Registering namespace prefixes
>>>>Date: Wed, 3 Dec 2003 12:32:23 -0500
>>>>Content-Type: text/plain;
>>>>charset="iso-8859-1"
>>>>
>>>>
>>>>
>>>>Hi All:
>>>>
>>>>Is there a way of registering a namespace prefix upfront in a
>>>>JXPathContext so that I can then use that prefix in xpath expressions?
>>>>Here's what I'm looking for, in pseudo-code.
>>>>
>>>>JXPathContext domContext = JXPathContext.newContext(document);
>>>>domContext.registerNamespace
>>>> (http://www.example.com/ns/sample, "prefix");
>>>>domContext.getValue("prefix:a/prefix:b");
>>>>
>>>>Thanks
>>>>chap
>>>>
>>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>>
>>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Dmitri Plotnikov <dm...@apache.org>.
Chap, Sudhir,
After some profound discussions on the jdom-interest@jdom.org mailing list,
I decided to roll back this new feature. I need to better understand the
use case before I introduce this new API.
Is the functionality you are referring to intended for use with Java
objects? What is the meaning of a namespace URI in the context of Java
objects? Please, give me as much information about this use case as
possible.
- Dmiri
----- Original Message -----
From: "Dmitri Plotnikov" <dm...@apache.org>
To: <ch...@hotmail.com>; "Jakarta Commons Users List"
<co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, January 17, 2004 8:52 PM
Subject: Re: [JXPath] Registering namespace prefixes
> Chap,
>
> I added registration of external namespaces to JXPath. My solution is a
> little different from the one proposed by Sudhir. The main difference in
> the API is that instead of calling registerNamespace directly on
> JXPathContext, you call it indirectly like this:
>
> JXPathContext context = JXPathContext.newContext(document);
> NamespaceManager nsm = context.getNamespaceManager();
> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
>
> Take a look at the NamespaceManager interface - you can supply your own
> implementation, which could perform very flexible customizations of
> namespace lookup.
>
> Please note that external namespaces are supported with DOM but not JDOM,
> because JDOM B9 at this point requires that all namespaces be explicitly
> declared in the XML file itself.
>
> Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
> they address your needs, I will highly appreciate it.
>
> Thanks,
>
> - Dmitri
>
>
> ----- Original Message -----
> From: "Sudhir Rao" <su...@att.net>
> To: <ch...@hotmail.com>
> Cc: <co...@jakarta.apache.org>
> Sent: Saturday, December 06, 2003 6:41 PM
> Subject: Re: [JXPath] Registering namespace prefixes
>
>
> > I made some local modifications for this. I am not sure if adding that
> > registerNamespace is the right way to do it, as I am not very familiar
> > with the codebase. The changes I did locally were to
> > a) Modify org.apache.commons.jxpath.ri.QName.java to include the
> > namespace prefix (similar to the one in Apache Axis). Had to tweak it a
> > bit to consider the prefix as the namespaceURI however to keep it
> > compatible with existing code.
> > b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
> > class.
> > c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
> > the QName instance returned.
> > d) Add the registerNamespace method to JXPathContextReferenceImpl and
> > JXPathContext which in turn call a registerNamespace in Compiler class.
> >
> > I can send across my changes if someone would like to look into it.
> >
> > -Sudhir
> >
> > >From: Prasad A. Chodavarapu <ch...@hotmail.com>
> > >Subject: [JXPath] Registering namespace prefixes
> > >Date: Wed, 3 Dec 2003 12:32:23 -0500
> > >Content-Type: text/plain;
> > > charset="iso-8859-1"
> > >
> > >
> > >
> > >Hi All:
> > >
> > >Is there a way of registering a namespace prefix upfront in a
> > >JXPathContext so that I can then use that prefix in xpath expressions?
> > >Here's what I'm looking for, in pseudo-code.
> > >
> > >JXPathContext domContext = JXPathContext.newContext(document);
> > >domContext.registerNamespace
> > > (http://www.example.com/ns/sample, "prefix");
> > >domContext.getValue("prefix:a/prefix:b");
> > >
> > >Thanks
> > >chap
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [JXPath] Registering namespace prefixes - never mind
Posted by Dmitri Plotnikov <dm...@apache.org>.
Chap, Sudhir,
After some profound discussions on the jdom-interest@jdom.org mailing list,
I decided to roll back this new feature. I need to better understand the
use case before I introduce this new API.
Is the functionality you are referring to intended for use with Java
objects? What is the meaning of a namespace URI in the context of Java
objects? Please, give me as much information about this use case as
possible.
- Dmiri
----- Original Message -----
From: "Dmitri Plotnikov" <dm...@apache.org>
To: <ch...@hotmail.com>; "Jakarta Commons Users List"
<co...@jakarta.apache.org>; ""Sudhir Rao"" <su...@att.net>
Cc: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Saturday, January 17, 2004 8:52 PM
Subject: Re: [JXPath] Registering namespace prefixes
> Chap,
>
> I added registration of external namespaces to JXPath. My solution is a
> little different from the one proposed by Sudhir. The main difference in
> the API is that instead of calling registerNamespace directly on
> JXPathContext, you call it indirectly like this:
>
> JXPathContext context = JXPathContext.newContext(document);
> NamespaceManager nsm = context.getNamespaceManager();
> nsm.registerNamespace ("prefix", "http://www.example.com/ns/sample");
>
> Take a look at the NamespaceManager interface - you can supply your own
> implementation, which could perform very flexible customizations of
> namespace lookup.
>
> Please note that external namespaces are supported with DOM but not JDOM,
> because JDOM B9 at this point requires that all namespaces be explicitly
> declared in the XML file itself.
>
> Chap, Sudhir, if you guys get a chance to try out the new APIs to see if
> they address your needs, I will highly appreciate it.
>
> Thanks,
>
> - Dmitri
>
>
> ----- Original Message -----
> From: "Sudhir Rao" <su...@att.net>
> To: <ch...@hotmail.com>
> Cc: <co...@jakarta.apache.org>
> Sent: Saturday, December 06, 2003 6:41 PM
> Subject: Re: [JXPath] Registering namespace prefixes
>
>
> > I made some local modifications for this. I am not sure if adding that
> > registerNamespace is the right way to do it, as I am not very familiar
> > with the codebase. The changes I did locally were to
> > a) Modify org.apache.commons.jxpath.ri.QName.java to include the
> > namespace prefix (similar to the one in Apache Axis). Had to tweak it a
> > bit to consider the prefix as the namespaceURI however to keep it
> > compatible with existing code.
> > b) Maintain a HashMap of prefixes to namespace URIs in the TreeCompiler
> > class.
> > c) Modify the TreeCompiler.qName(..) to populate the namespace URI in
> > the QName instance returned.
> > d) Add the registerNamespace method to JXPathContextReferenceImpl and
> > JXPathContext which in turn call a registerNamespace in Compiler class.
> >
> > I can send across my changes if someone would like to look into it.
> >
> > -Sudhir
> >
> > >From: Prasad A. Chodavarapu <ch...@hotmail.com>
> > >Subject: [JXPath] Registering namespace prefixes
> > >Date: Wed, 3 Dec 2003 12:32:23 -0500
> > >Content-Type: text/plain;
> > > charset="iso-8859-1"
> > >
> > >
> > >
> > >Hi All:
> > >
> > >Is there a way of registering a namespace prefix upfront in a
> > >JXPathContext so that I can then use that prefix in xpath expressions?
> > >Here's what I'm looking for, in pseudo-code.
> > >
> > >JXPathContext domContext = JXPathContext.newContext(document);
> > >domContext.registerNamespace
> > > (http://www.example.com/ns/sample, "prefix");
> > >domContext.getValue("prefix:a/prefix:b");
> > >
> > >Thanks
> > >chap
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org