Jaxen 1.1.1 and duplicated Namespaces' prefixes

View: New views
6 Messages — Rating Filter:   Alert me  

Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Dobri Kitipov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I want to ask you if it is possible to have the following xml with duplicated namespaces' prefixes. Sample:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:ns="http://foo.org/my2" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <soapenv:Header>
    </soapenv:Header>
    <soapenv:Body>
        <ns:echo xmlns:ns="http://foo.org/my">
            <ns:name>Dodo</ns:name>
        </ns:echo>
    </soapenv:Body>
</soapenv:Envelope>

The duplicated namespaces are:

xmlns:ns="http://foo.org/my2"
and
xmlns:ns="http://foo.org/my"

We can read from "Namespaces in XML 1.0 (Second Edition)":

{6 Applying Namespaces to Elements and Attributes
6.1 Namespace Scoping

The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag, excluding the scope of any inner declarations with the same NSAttName part. In the case of an empty tag, the scope is the tag itself.}

It seems to me that it is legal to have the same prefixes. The sample xml is also accepted by XMLSpy, too (i.e. it says that the sample is well formated).

THE PROBLEM:

The problem is that Jaxen does not have notion of to which tag a given namespace is associated with? So when namespaces are declared it is importand in which order this is done:

        contextpath.addNamespace("ns", "http://foo.org/my2");
        contextpath.addNamespace("ns", "http://foo.org/my");

or

        contextpath.addNamespace("ns", "http://foo.org/my");
        contextpath.addNamespace("ns", "http://foo.org/my2");

in the former case Jaxen will found the xPath = "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it will NOT. This is because all namespaces are put into a common namespaces' HashMap and as a key it is used the prefix. So the order of putting them into it is crucial.

If the sample xml is valid then I can share my ideas for a fix (e.g. use the uri).

I will appreciate any thoughts on this.

Thanks,
Dobri

Re: Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Baz-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:

> Hi all,
> I want to ask you if it is possible to have the following xml with
> duplicated namespaces' prefixes. Sample:
>
> <?xml version="1.0" encoding="utf-8"?>
> <soapenv:Envelope xmlns:ns="http://foo.org/my2"
> xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
>     <soapenv:Header>
>     </soapenv:Header>
>     <soapenv:Body>
>         <ns:echo xmlns:ns="http://foo.org/my">
>             <ns:name>Dodo</ns:name>
>         </ns:echo>
>     </soapenv:Body>
> </soapenv:Envelope>
>
> The duplicated namespaces are:
>
> xmlns:ns="http://foo.org/my2"
> and
> xmlns:ns="http://foo.org/my"
>
> We can read from "Namespaces in XML 1.0 (Second Edition)":
>
> {6 Applying Namespaces to Elements and Attributes
> 6.1 Namespace Scoping
>
> The scope of a namespace declaration declaring a prefix extends from the
> beginning of the start-tag in which it appears to the end of the
> corresponding end-tag, excluding the scope of any inner declarations with
> the same NSAttName part. In the case of an empty tag, the scope is the tag
> itself.}
>
> It seems to me that it is legal to have the same prefixes. The sample xml is
> also accepted by XMLSpy, too (i.e. it says that the sample is well
> formated).

Yes, it is legal to have two namespaces with the same prefix, But they
are never in scope at the same time.

>
> THE PROBLEM:
>
> The problem is that Jaxen does not have notion of to which tag a given
> namespace is associated with? So when namespaces are declared it is
> importand in which order this is done:
>
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>         contextpath.addNamespace("ns", "http://foo.org/my");
>
> or
>
>         contextpath.addNamespace("ns", "http://foo.org/my");
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>
> in the former case Jaxen will found the xPath =
> "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it will
> NOT. This is because all namespaces are put into a common namespaces'
> HashMap and as a key it is used the prefix. So the order of putting them
> into it is crucial.

No. Only the last prefix registration counts; this is not the same
thing as them being 'ordered'.

> If the sample xml is valid then I can share my ideas for a fix (e.g. use the
> uri).

The xml is valid, but your understanding of xpath is incorrect. The
prefixes used in your document simply do not matter - only the
namespaces matter. So, eg:
 contextpath.addNamespace("bubble", "http://www.w3.org/2003/05/soap-envelope");
 contextpath.addNamespace("foo", "http://foo.org/my");
will allow the xpath:
"/bubble:Envelope/bubble:Body/foo:echo/foo:name"
... to find the node in your document. Note that none of the prefixes
match those in your document.

A particularly stark example, showing that document namespace prefixes
are not used by xpath, is if I used the document:
<foo xmlns="http://foo.org/my"/>

In this case, not only does "/foo" match nothing, but you /cannot/ call:
 contextpath.addNamespace("", "http://foo.org/my");
to register the default namespace - the default namespace for xpath
always means 'no namespace'. (see section 2.3 of
http://www.w3.org/TR/xpath )

>
> I will appreciate any thoughts on this.
>
> Thanks,
> Dobri
>

Cheers,
Baz

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Dobri Kitipov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Jun 1, 2009 at 5:44 PM, Baz <brian.ewins@...> wrote:
2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:
> Hi all,
> I want to ask you if it is possible to have the following xml with
> duplicated namespaces' prefixes. Sample:
>
> <?xml version="1.0" encoding="utf-8"?>
> <soapenv:Envelope xmlns:ns="http://foo.org/my2"
> xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
>     <soapenv:Header>
>     </soapenv:Header>
>     <soapenv:Body>
>         <ns:echo xmlns:ns="http://foo.org/my">
>             <ns:name>Dodo</ns:name>
>         </ns:echo>
>     </soapenv:Body>
> </soapenv:Envelope>
>
> The duplicated namespaces are:
>
> xmlns:ns="http://foo.org/my2"
> and
> xmlns:ns="http://foo.org/my"
>
> We can read from "Namespaces in XML 1.0 (Second Edition)":
>
> {6 Applying Namespaces to Elements and Attributes
> 6.1 Namespace Scoping
>
> The scope of a namespace declaration declaring a prefix extends from the
> beginning of the start-tag in which it appears to the end of the
> corresponding end-tag, excluding the scope of any inner declarations with
> the same NSAttName part. In the case of an empty tag, the scope is the tag
> itself.}
>
> It seems to me that it is legal to have the same prefixes. The sample xml is
> also accepted by XMLSpy, too (i.e. it says that the sample is well
> formated).

Yes, it is legal to have two namespaces with the same prefix, But they
are never in scope at the same time.

Dobri:
Yes, that is right. I know that. The real problem is that two namespaces with the same prefix cannot be registered to the contextpath. Underneath HashMap is used, and that is the explanation.


>
> THE PROBLEM:
>
> The problem is that Jaxen does not have notion of to which tag a given
> namespace is associated with? So when namespaces are declared it is
> importand in which order this is done:
>
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>         contextpath.addNamespace("ns", "http://foo.org/my");
>
> or
>
>         contextpath.addNamespace("ns", "http://foo.org/my");
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>
> in the former case Jaxen will found the xPath =
> "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it will
> NOT. This is because all namespaces are put into a common namespaces'
> HashMap and as a key it is used the prefix. So the order of putting them
> into it is crucial.

No. Only the last prefix registration counts; this is not the same
thing as them being 'ordered'.

Dobri:
Right, I am aware of that. I mean that you will have different results depending on the order in which namespaces with the same prefix are added to the contextpath.
 


> If the sample xml is valid then I can share my ideas for a fix (e.g. use the
> uri).

The xml is valid, but your understanding of xpath is incorrect. The
prefixes used in your document simply do not matter - only the
namespaces matter. So, eg:
 contextpath.addNamespace("bubble", "http://www.w3.org/2003/05/soap-envelope");
 contextpath.addNamespace("foo", "http://foo.org/my");
will allow the xpath:
"/bubble:Envelope/bubble:Body/foo:echo/foo:name"
... to find the node in your document. Note that none of the prefixes
match those in your document.

A particularly stark example, showing that document namespace prefixes
are not used by xpath, is if I used the document:
<foo xmlns="http://foo.org/my"/>

In this case, not only does "/foo" match nothing, but you /cannot/ call:
 contextpath.addNamespace("", "http://foo.org/my");
to register the default namespace - the default namespace for xpath
always means 'no namespace'. (see section 2.3 of
http://www.w3.org/TR/xpath )

Dobri:
I know that the URI matters not the prefix, but may be you are right. I should miss something.

Let me explain it again. The problem is that Jaxen uses prefixes to register URIs. So how will you force Jaxen to parse my sample without touching the prefixes into the sample xml??? How will you add to the contextpath two DIFFERENT URIs under that uses the SAME prefix? This is the important question.

I did a workaround/patch creating an aggregate key (prefix+uri) in this exotic scenarion and it works fine for me.


>
> I will appreciate any thoughts on this.
>
> Thanks,
> Dobri
>

Cheers,
Baz

Thank you,
Dobri
 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Re: Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Dobri Kitipov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Baz,
I want to write you that I am getting your idea. If I change the prefixes into the XPath expresson and register them into the contextpath, under different prefixes, everything will work fine. But this will work if you have a control to do that.

Let me think for more use cases, so I will approach you later if I have any questions.

Thank you,
Dobri

On Mon, Jun 1, 2009 at 6:31 PM, Dobri Kitipov <kdobrik.axis2@...> wrote:


On Mon, Jun 1, 2009 at 5:44 PM, Baz <brian.ewins@...> wrote:
2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:
> Hi all,
> I want to ask you if it is possible to have the following xml with
> duplicated namespaces' prefixes. Sample:
>
> <?xml version="1.0" encoding="utf-8"?>
> <soapenv:Envelope xmlns:ns="http://foo.org/my2"
> xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
> xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
>     <soapenv:Header>
>     </soapenv:Header>
>     <soapenv:Body>
>         <ns:echo xmlns:ns="http://foo.org/my">
>             <ns:name>Dodo</ns:name>
>         </ns:echo>
>     </soapenv:Body>
> </soapenv:Envelope>
>
> The duplicated namespaces are:
>
> xmlns:ns="http://foo.org/my2"
> and
> xmlns:ns="http://foo.org/my"
>
> We can read from "Namespaces in XML 1.0 (Second Edition)":
>
> {6 Applying Namespaces to Elements and Attributes
> 6.1 Namespace Scoping
>
> The scope of a namespace declaration declaring a prefix extends from the
> beginning of the start-tag in which it appears to the end of the
> corresponding end-tag, excluding the scope of any inner declarations with
> the same NSAttName part. In the case of an empty tag, the scope is the tag
> itself.}
>
> It seems to me that it is legal to have the same prefixes. The sample xml is
> also accepted by XMLSpy, too (i.e. it says that the sample is well
> formated).

Yes, it is legal to have two namespaces with the same prefix, But they
are never in scope at the same time.

Dobri:
Yes, that is right. I know that. The real problem is that two namespaces with the same prefix cannot be registered to the contextpath. Underneath HashMap is used, and that is the explanation.


>
> THE PROBLEM:
>
> The problem is that Jaxen does not have notion of to which tag a given
> namespace is associated with? So when namespaces are declared it is
> importand in which order this is done:
>
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>         contextpath.addNamespace("ns", "http://foo.org/my");
>
> or
>
>         contextpath.addNamespace("ns", "http://foo.org/my");
>         contextpath.addNamespace("ns", "http://foo.org/my2");
>
> in the former case Jaxen will found the xPath =
> "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it will
> NOT. This is because all namespaces are put into a common namespaces'
> HashMap and as a key it is used the prefix. So the order of putting them
> into it is crucial.

No. Only the last prefix registration counts; this is not the same
thing as them being 'ordered'.

Dobri:
Right, I am aware of that. I mean that you will have different results depending on the order in which namespaces with the same prefix are added to the contextpath.
 


> If the sample xml is valid then I can share my ideas for a fix (e.g. use the
> uri).

The xml is valid, but your understanding of xpath is incorrect. The
prefixes used in your document simply do not matter - only the
namespaces matter. So, eg:
 contextpath.addNamespace("bubble", "http://www.w3.org/2003/05/soap-envelope");
 contextpath.addNamespace("foo", "http://foo.org/my");
will allow the xpath:
"/bubble:Envelope/bubble:Body/foo:echo/foo:name"
... to find the node in your document. Note that none of the prefixes
match those in your document.

A particularly stark example, showing that document namespace prefixes
are not used by xpath, is if I used the document:
<foo xmlns="http://foo.org/my"/>

In this case, not only does "/foo" match nothing, but you /cannot/ call:
 contextpath.addNamespace("", "http://foo.org/my");
to register the default namespace - the default namespace for xpath
always means 'no namespace'. (see section 2.3 of
http://www.w3.org/TR/xpath )

Dobri:
I know that the URI matters not the prefix, but may be you are right. I should miss something.

Let me explain it again. The problem is that Jaxen uses prefixes to register URIs. So how will you force Jaxen to parse my sample without touching the prefixes into the sample xml??? How will you add to the contextpath two DIFFERENT URIs under that uses the SAME prefix? This is the important question.

I did a workaround/patch creating an aggregate key (prefix+uri) in this exotic scenarion and it works fine for me.


>
> I will appreciate any thoughts on this.
>
> Thanks,
> Dobri
>

Cheers,
Baz

Thank you,
Dobri
 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





Re: Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Baz-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:

>
>
> On Mon, Jun 1, 2009 at 5:44 PM, Baz <brian.ewins@...> wrote:
>>
>> 2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:
>> > Hi all,
>> > I want to ask you if it is possible to have the following xml with
>> > duplicated namespaces' prefixes. Sample:
>> >
>> > <?xml version="1.0" encoding="utf-8"?>
>> > <soapenv:Envelope xmlns:ns="http://foo.org/my2"
>> > xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
>> > xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
>> >     <soapenv:Header>
>> >     </soapenv:Header>
>> >     <soapenv:Body>
>> >         <ns:echo xmlns:ns="http://foo.org/my">
>> >             <ns:name>Dodo</ns:name>
>> >         </ns:echo>
>> >     </soapenv:Body>
>> > </soapenv:Envelope>
>> >
>> > The duplicated namespaces are:
>> >
>> > xmlns:ns="http://foo.org/my2"
>> > and
>> > xmlns:ns="http://foo.org/my"
>> >
>> > We can read from "Namespaces in XML 1.0 (Second Edition)":
>> >
>> > {6 Applying Namespaces to Elements and Attributes
>> > 6.1 Namespace Scoping
>> >
>> > The scope of a namespace declaration declaring a prefix extends from the
>> > beginning of the start-tag in which it appears to the end of the
>> > corresponding end-tag, excluding the scope of any inner declarations
>> > with
>> > the same NSAttName part. In the case of an empty tag, the scope is the
>> > tag
>> > itself.}
>> >
>> > It seems to me that it is legal to have the same prefixes. The sample
>> > xml is
>> > also accepted by XMLSpy, too (i.e. it says that the sample is well
>> > formated).
>>
>> Yes, it is legal to have two namespaces with the same prefix, But they
>> are never in scope at the same time.
>
> Dobri:
> Yes, that is right. I know that. The real problem is that two namespaces
> with the same prefix cannot be registered to the contextpath. Underneath
> HashMap is used, and that is the explanation.

No, here you're confusing our implementation with the spec. The
specification for xpath says (in section 1):

"Expression evaluation occurs with respect to a context. XSLT and
XPointer specify how the context is determined for XPath expressions
used in XSLT and XPointer respectively. The context [includes] the set
of namespace declarations in scope for the expression[...]The
namespace declarations consist of a mapping from prefixes to namespace
URIs."

>>
>>
>> >
>> > THE PROBLEM:
>> >
>> > The problem is that Jaxen does not have notion of to which tag a given
>> > namespace is associated with? So when namespaces are declared it is
>> > importand in which order this is done:
>> >
>> >         contextpath.addNamespace("ns", "http://foo.org/my2");
>> >         contextpath.addNamespace("ns", "http://foo.org/my");
>> >
>> > or
>> >
>> >         contextpath.addNamespace("ns", "http://foo.org/my");
>> >         contextpath.addNamespace("ns", "http://foo.org/my2");
>> >
>> > in the former case Jaxen will found the xPath =
>> > "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it
>> > will
>> > NOT. This is because all namespaces are put into a common namespaces'
>> > HashMap and as a key it is used the prefix. So the order of putting them
>> > into it is crucial.
>>
>> No. Only the last prefix registration counts; this is not the same
>> thing as them being 'ordered'.
>
> Dobri:
> Right, I am aware of that. I mean that you will have different results
> depending on the order in which namespaces with the same prefix are added to
> the contextpath.

Not really. If you try to add N mappings from prefix 'x' to a
namespace, only the last one matters. None of the previous N-1 counts.

It's the same as saying:
x=1;
x=2;
x=3; // only this value counts
its not an ordering issue - its a bug when you include code that does nothing.
(I apologize if this is already clear to you, but your description
could mislead other coders who get here via google)

>
>>
>> > If the sample xml is valid then I can share my ideas for a fix (e.g. use
>> > the
>> > uri).
>>
>> The xml is valid, but your understanding of xpath is incorrect. The
>> prefixes used in your document simply do not matter - only the
>> namespaces matter. So, eg:
>>  contextpath.addNamespace("bubble",
>> "http://www.w3.org/2003/05/soap-envelope");
>>  contextpath.addNamespace("foo", "http://foo.org/my");
>> will allow the xpath:
>> "/bubble:Envelope/bubble:Body/foo:echo/foo:name"
>> ... to find the node in your document. Note that none of the prefixes
>> match those in your document.
>>
>> A particularly stark example, showing that document namespace prefixes
>> are not used by xpath, is if I used the document:
>> <foo xmlns="http://foo.org/my"/>
>>
>> In this case, not only does "/foo" match nothing, but you /cannot/ call:
>>  contextpath.addNamespace("", "http://foo.org/my");
>> to register the default namespace - the default namespace for xpath
>> always means 'no namespace'. (see section 2.3 of
>> http://www.w3.org/TR/xpath )
>
> Dobri:
> I know that the URI matters not the prefix, but may be you are right. I
> should miss something.
>
> Let me explain it again. The problem is that Jaxen uses prefixes to register
> URIs. So how will you force Jaxen to parse my sample without touching the
> prefixes into the sample xml??? How will you add to the contextpath two
> DIFFERENT URIs under that uses the SAME prefix? This is the important
> question.

You declare different prefixes for each namespace in your document in
the xpath context- no need to touch the document - and use THOSE
prefixes in your xpath. Again, NONE of these prefixes need to match
those in your document. If you have one prefix that maps to two URIs
in your document, you are still free to use two DIFFERENT prefixes in
your xpath, and this is the solution you're looking for.

>
> I did a workaround/patch creating an aggregate key (prefix+uri) in this
> exotic scenarion and it works fine for me.
>
>>
>> >
>> > I will appreciate any thoughts on this.
>> >
>> > Thanks,
>> > Dobri
>> >
>>
>> Cheers,
>> Baz
>
> Thank you,
> Dobri

No problem,
Baz

>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Jaxen 1.1.1 and duplicated Namespaces' prefixes

by Dobri Kitipov-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you Baz!
I really appreciate your help.
Now it is totally clear for me.

It seems I was mislead by thinking that the prefix used into the payload was to be used to get the URI registered into the namespace HashMap.

Refer to DefaultNameStep#matches(Object, ContextSupport):

myUri = contextSupport.translateNamespacePrefixToUri(this.prefix);

But since the "this.prefix" is not the one from the payload but the one specified into the XPath there is no problem :)

Thanks,
Dobri

On Tue, Jun 2, 2009 at 3:13 AM, Baz <brian.ewins@...> wrote:
2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:
>
>
> On Mon, Jun 1, 2009 at 5:44 PM, Baz <brian.ewins@...> wrote:
>>
>> 2009/6/1 Dobri Kitipov <kdobrik.axis2@...>:
>> > Hi all,
>> > I want to ask you if it is possible to have the following xml with
>> > duplicated namespaces' prefixes. Sample:
>> >
>> > <?xml version="1.0" encoding="utf-8"?>
>> > <soapenv:Envelope xmlns:ns="http://foo.org/my2"
>> > xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
>> > xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
>> >     <soapenv:Header>
>> >     </soapenv:Header>
>> >     <soapenv:Body>
>> >         <ns:echo xmlns:ns="http://foo.org/my">
>> >             <ns:name>Dodo</ns:name>
>> >         </ns:echo>
>> >     </soapenv:Body>
>> > </soapenv:Envelope>
>> >
>> > The duplicated namespaces are:
>> >
>> > xmlns:ns="http://foo.org/my2"
>> > and
>> > xmlns:ns="http://foo.org/my"
>> >
>> > We can read from "Namespaces in XML 1.0 (Second Edition)":
>> >
>> > {6 Applying Namespaces to Elements and Attributes
>> > 6.1 Namespace Scoping
>> >
>> > The scope of a namespace declaration declaring a prefix extends from the
>> > beginning of the start-tag in which it appears to the end of the
>> > corresponding end-tag, excluding the scope of any inner declarations
>> > with
>> > the same NSAttName part. In the case of an empty tag, the scope is the
>> > tag
>> > itself.}
>> >
>> > It seems to me that it is legal to have the same prefixes. The sample
>> > xml is
>> > also accepted by XMLSpy, too (i.e. it says that the sample is well
>> > formated).
>>
>> Yes, it is legal to have two namespaces with the same prefix, But they
>> are never in scope at the same time.
>
> Dobri:
> Yes, that is right. I know that. The real problem is that two namespaces
> with the same prefix cannot be registered to the contextpath. Underneath
> HashMap is used, and that is the explanation.

No, here you're confusing our implementation with the spec. The
specification for xpath says (in section 1):

"Expression evaluation occurs with respect to a context. XSLT and
XPointer specify how the context is determined for XPath expressions
used in XSLT and XPointer respectively. The context [includes] the set
of namespace declarations in scope for the expression[...]The
namespace declarations consist of a mapping from prefixes to namespace
URIs."

>>
>>
>> >
>> > THE PROBLEM:
>> >
>> > The problem is that Jaxen does not have notion of to which tag a given
>> > namespace is associated with? So when namespaces are declared it is
>> > importand in which order this is done:
>> >
>> >         contextpath.addNamespace("ns", "http://foo.org/my2");
>> >         contextpath.addNamespace("ns", "http://foo.org/my");
>> >
>> > or
>> >
>> >         contextpath.addNamespace("ns", "http://foo.org/my");
>> >         contextpath.addNamespace("ns", "http://foo.org/my2");
>> >
>> > in the former case Jaxen will found the xPath =
>> > "/soapenv:Envelope/soapenv:Body/ns:echo/ns:name", but in the latter it
>> > will
>> > NOT. This is because all namespaces are put into a common namespaces'
>> > HashMap and as a key it is used the prefix. So the order of putting them
>> > into it is crucial.
>>
>> No. Only the last prefix registration counts; this is not the same
>> thing as them being 'ordered'.
>
> Dobri:
> Right, I am aware of that. I mean that you will have different results
> depending on the order in which namespaces with the same prefix are added to
> the contextpath.

Not really. If you try to add N mappings from prefix 'x' to a
namespace, only the last one matters. None of the previous N-1 counts.

It's the same as saying:
x=1;
x=2;
x=3; // only this value counts
its not an ordering issue - its a bug when you include code that does nothing.
(I apologize if this is already clear to you, but your description
could mislead other coders who get here via google)

>
>>
>> > If the sample xml is valid then I can share my ideas for a fix (e.g. use
>> > the
>> > uri).
>>
>> The xml is valid, but your understanding of xpath is incorrect. The
>> prefixes used in your document simply do not matter - only the
>> namespaces matter. So, eg:
>>  contextpath.addNamespace("bubble",
>> "http://www.w3.org/2003/05/soap-envelope");
>>  contextpath.addNamespace("foo", "http://foo.org/my");
>> will allow the xpath:
>> "/bubble:Envelope/bubble:Body/foo:echo/foo:name"
>> ... to find the node in your document. Note that none of the prefixes
>> match those in your document.
>>
>> A particularly stark example, showing that document namespace prefixes
>> are not used by xpath, is if I used the document:
>> <foo xmlns="http://foo.org/my"/>
>>
>> In this case, not only does "/foo" match nothing, but you /cannot/ call:
>>  contextpath.addNamespace("", "http://foo.org/my");
>> to register the default namespace - the default namespace for xpath
>> always means 'no namespace'. (see section 2.3 of
>> http://www.w3.org/TR/xpath )
>
> Dobri:
> I know that the URI matters not the prefix, but may be you are right. I
> should miss something.
>
> Let me explain it again. The problem is that Jaxen uses prefixes to register
> URIs. So how will you force Jaxen to parse my sample without touching the
> prefixes into the sample xml??? How will you add to the contextpath two
> DIFFERENT URIs under that uses the SAME prefix? This is the important
> question.

You declare different prefixes for each namespace in your document in
the xpath context- no need to touch the document - and use THOSE
prefixes in your xpath. Again, NONE of these prefixes need to match
those in your document. If you have one prefix that maps to two URIs
in your document, you are still free to use two DIFFERENT prefixes in
your xpath, and this is the solution you're looking for.

>
> I did a workaround/patch creating an aggregate key (prefix+uri) in this
> exotic scenarion and it works fine for me.
>
>>
>> >
>> > I will appreciate any thoughts on this.
>> >
>> > Thanks,
>> > Dobri
>> >
>>
>> Cheers,
>> Baz
>
> Thank you,
> Dobri

No problem,
Baz

>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email