You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Gianugo Rabellino <gi...@apache.org> on 2004/02/13 18:03:28 UTC

Woody binding of namespaced element

... I still consider myself quite a newbie on Woody, but I'm facing 
a tough issue. I need to bind a woody form to some namespaced XML (a 
SourcePropsWritingTransformer input, in case you were wondering), 
introducing an element with a new namespace. My binding file so far 
is as simple as:

<wb:context xmlns:wb="http://apache.org/cocoon/woody/binding/1.0"
             xmlns:swpt="http://apache.org/cocoon/propwrite/1.0"
             xmlns:test="http://test.com/test/1.0"
             path="/source:patch/source:set">
     <wb:value id="status" path="test:status"/>
</wb:context>

problem is that in my output I get:


<swpt:patch xmlns:swpt="http://apache.org/cocoon/propwrite/1.0">
   <swpt:source>webdav://localhost/dav/test.xml</swpt:source>
   <swpt:set>
      <test:status>publish</test:status>
    </swpt:set>
</swpt:patch>

where you can notice that the element is created in a correct way, 
but the namespace is _not_ declared, so the output is not 
well-formed XML.

Apart from some obnoxious XSLT tricks that would get the job done, I 
was wondering if I'm doing something obviously wrong, so I'm asking 
for your advice before starting to dig the quite scary Woody code. :-)

-- 
Gianugo Rabellino
Pro-netics s.r.l. -  http://www.pro-netics.com
Orixo, the XML business alliance - http://www.orixo.com
     (Blogging at: http://www.rabellino.it/blog/)

Re: Woody binding of namespaced element

Posted by Christopher Oliver <re...@verizon.net>.
Considering the widespread use of JXPath in Cocoon, this seems like a 
good opportunity for some Cocoon developers to help Dmitri add this 
feature to JXPath:
http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=107454542000704&w=2

Regards,

Chris

Gianugo Rabellino wrote:

> Sylvain Wallez wrote:
>
>> Gianugo Rabellino wrote:
>>
>>> Christopher Oliver wrote:
>>>
>>>> That is a problem with JXPath. I may be wrong, but if IIRC it 
>>>> doesn't support namespaces properly or at all.
>>>
>>>
>>>
>>>
>>> Bad bad news. Actually it seems to do selections just fine, but 
>>> insertions are flawed. OK, time for tricks then :-/
>>
>>
>>
>>
>> AFAIK, even for selection you may encounter problems as the prefix is 
>> used, but the actual namespace URI is ignored.
>>
>> There may be a workaround for the binding, however: the 
>> o.a.c.util.jxpath.DOMFactory class tries to guess the namespace URI 
>> when asked to create a prefixed element by crawling up the DOM tree 
>> up to finding an "xmlns:" namespace declaration attribute for that 
>> prefix.
>>
>> So if you add that declaration on the root element of the document 
>> you bind to, prefixed elements should be correctly namespaced.
>
>
> Will give it a try, thanks. It would work much better than what I'm 
> using now (a hacky transformer that gets prefix->namespace mappings 
> from external files and plugs them "on the fly" when it gets a null or 
> empty nsURI for a qualified start/endElement). Actually, however, my 
> problem was in SAX parsing to a SourcePropWritingTransfomer, where I 
> got a DOM Namespace error. Will see if your workaround fixex that.
>
> Thanks so much,
>


Re: Woody binding of namespaced element

Posted by Gianugo Rabellino <gi...@apache.org>.
Sylvain Wallez wrote:
> Gianugo Rabellino wrote:
> 
>> Christopher Oliver wrote:
>>
>>> That is a problem with JXPath. I may be wrong, but if IIRC it doesn't 
>>> support namespaces properly or at all.
>>
>>
>>
>> Bad bad news. Actually it seems to do selections just fine, but 
>> insertions are flawed. OK, time for tricks then :-/
> 
> 
> 
> AFAIK, even for selection you may encounter problems as the prefix is 
> used, but the actual namespace URI is ignored.
> 
> There may be a workaround for the binding, however: the 
> o.a.c.util.jxpath.DOMFactory class tries to guess the namespace URI when 
> asked to create a prefixed element by crawling up the DOM tree up to 
> finding an "xmlns:" namespace declaration attribute for that prefix.
> 
> So if you add that declaration on the root element of the document you 
> bind to, prefixed elements should be correctly namespaced.

Will give it a try, thanks. It would work much better than what I'm 
using now (a hacky transformer that gets prefix->namespace mappings 
from external files and plugs them "on the fly" when it gets a null 
or empty nsURI for a qualified start/endElement). Actually, however, 
my problem was in SAX parsing to a SourcePropWritingTransfomer, 
where I got a DOM Namespace error. Will see if your workaround fixex 
that.

Thanks so much,

-- 
Gianugo Rabellino
Pro-netics s.r.l. -  http://www.pro-netics.com
Orixo, the XML business alliance - http://www.orixo.com
     (Blogging at: http://www.rabellino.it/blog/)

Re: Woody binding of namespaced element

Posted by Sylvain Wallez <sy...@apache.org>.
Gianugo Rabellino wrote:

> Christopher Oliver wrote:
>
>> That is a problem with JXPath. I may be wrong, but if IIRC it doesn't 
>> support namespaces properly or at all.
>
>
> Bad bad news. Actually it seems to do selections just fine, but 
> insertions are flawed. OK, time for tricks then :-/


AFAIK, even for selection you may encounter problems as the prefix is 
used, but the actual namespace URI is ignored.

There may be a workaround for the binding, however: the 
o.a.c.util.jxpath.DOMFactory class tries to guess the namespace URI when 
asked to create a prefixed element by crawling up the DOM tree up to 
finding an "xmlns:" namespace declaration attribute for that prefix.

So if you add that declaration on the root element of the document you 
bind to, prefixed elements should be correctly namespaced.

Hope this helps,
Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com




Re: Woody binding of namespaced element

Posted by Gianugo Rabellino <gi...@apache.org>.
Christopher Oliver wrote:
> That is a problem with JXPath. I may be wrong, but if IIRC it doesn't 
> support namespaces properly or at all.

Bad bad news. Actually it seems to do selections just fine, but 
insertions are flawed. OK, time for tricks then :-/

Thanks anyway,

-- 
Gianugo Rabellino
Pro-netics s.r.l. -  http://www.pro-netics.com
Orixo, the XML business alliance - http://www.orixo.com
     (Blogging at: http://www.rabellino.it/blog/)

Re: Woody binding of namespaced element

Posted by Christopher Oliver <re...@verizon.net>.
That is a problem with JXPath. I may be wrong, but if IIRC it doesn't 
support namespaces properly or at all.

Gianugo Rabellino wrote:

> ... I still consider myself quite a newbie on Woody, but I'm facing a 
> tough issue. I need to bind a woody form to some namespaced XML (a 
> SourcePropsWritingTransformer input, in case you were wondering), 
> introducing an element with a new namespace. My binding file so far is 
> as simple as:
>
> <wb:context xmlns:wb="http://apache.org/cocoon/woody/binding/1.0"
>             xmlns:swpt="http://apache.org/cocoon/propwrite/1.0"
>             xmlns:test="http://test.com/test/1.0"
>             path="/source:patch/source:set">
>     <wb:value id="status" path="test:status"/>
> </wb:context>
>
> problem is that in my output I get:
>
>
> <swpt:patch xmlns:swpt="http://apache.org/cocoon/propwrite/1.0">
>   <swpt:source>webdav://localhost/dav/test.xml</swpt:source>
>   <swpt:set>
>      <test:status>publish</test:status>
>    </swpt:set>
> </swpt:patch>
>
> where you can notice that the element is created in a correct way, but 
> the namespace is _not_ declared, so the output is not well-formed XML.
>
> Apart from some obnoxious XSLT tricks that would get the job done, I 
> was wondering if I'm doing something obviously wrong, so I'm asking 
> for your advice before starting to dig the quite scary Woody code. :-)
>