commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sudhir Rao <>
Subject Re: [JXPath] Registering namespace prefixes - never mind
Date Tue, 20 Jan 2004 22:45:17 GMT

       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=''
        <bk:title>Cheaper by the Dozen</bk:title>
|    To access say the isbn number I would use the following xpath in my 
    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=''
        <ck:title>Cheaper by the Dozen</ck:title>

|    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.

Dmitri Plotnikov wrote:

>Chap, Sudhir,
>After some profound discussions on the 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
>- Dmiri
>----- Original Message ----- 
>From: "Dmitri Plotnikov" <>
>To: <>; "Jakarta Commons Users List"
><>; ""Sudhir Rao"" <>
>Cc: "Jakarta Commons Developers List" <>
>Sent: Saturday, January 17, 2004 8:52 PM
>Subject: Re: [JXPath] Registering namespace prefixes
>>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", "");
>>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.
>>- Dmitri
>>----- Original Message ----- 
>>From: "Sudhir Rao" <>
>>To: <>
>>Cc: <>
>>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 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
>>>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.
>>>>From: Prasad A. Chodavarapu <>
>>>>Subject: [JXPath] Registering namespace prefixes
>>>>Date: Wed, 3 Dec 2003 12:32:23 -0500
>>>>Content-Type: text/plain;
>>>>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);
>>>> (, "prefix");
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message