You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stephan Michels <st...@apache.org> on 2003/04/22 10:45:02 UTC

[XMLForm] Declarative xmlns attribute

Hi,

I have some problems with the following line of the XMLFormTransformer

 atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA", NS);

Xalan throw a violation exception, because you shouldn't set xmlns
attribute manually.

Can we remove this line?

BTW, I don't see a startPrefixMapping within the transformer.

Stephan.

_______________________________________________________________________
         Stephan Michels               EMail: stephan@apache.org
         ICQ: 115535699                Tel: +49-030-314-21583
----+----|----+----|----+----|----+----|----+----|----+----|----+----|-|



Re: [XMLForm] Declarative xmlns attribute

Posted by ivelin <iv...@apache.org>.
-=Ivelin=-
----- Original Message -----
From: "Bruno Dumon" <br...@outerthought.org>
To: <co...@xml.apache.org>
Sent: Tuesday, April 22, 2003 4:15 AM
Subject: Re: [XMLForm] Declarative xmlns attribute


> On Tue, 2003-04-22 at 10:45, Stephan Michels wrote:
> > Hi,
> >
> > I have some problems with the following line of the XMLFormTransformer
> >
> >  atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX,
"CDATA", NS);
>
> Unrelated note: in SAX, empty namespaces should be empty strings (""),
> not null.

Thanks. Took this note into account.

Ivelin


Re: [XMLForm] Declarative xmlns attribute

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2003-04-22 at 10:45, Stephan Michels wrote:
> Hi,
> 
> I have some problems with the following line of the XMLFormTransformer
> 
>  atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA", NS);

Unrelated note: in SAX, empty namespaces should be empty strings (""),
not null.

> 
> Xalan throw a violation exception, because you shouldn't set xmlns
> attribute manually.
> 
> Can we remove this line?

I assume so.

> 
> BTW, I don't see a startPrefixMapping within the transformer.

This is a potential problem. I assume nobody noticed it yet because they
are always using the same prefix.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: [XMLForm] Declarative xmlns attribute

Posted by Vadim Gritsenko <va...@verizon.net>.
ivelin wrote:

>Ok, here is what I tried, but not quite sure if it is correct.
>
>AttributesImpl atts;
>if (attributes == null || attributes.getLength() == 0) {
>atts = new AttributesImpl();
>} else {
>atts = new AttributesImpl(attributes);
>}
>startPrefixMapping(NS_PREFIX, NS);
>atts.addAttribute( "", NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA",
>NS);
>attributes = atts;
>
>The gist is that startPrefixMapping is immediately followed by an explicit
>attribute.
>The reason I did this is because without passing an explicit attribute,
>org.apache.xalan.serialize.SerializerToXML does not output it.
>Its startPrefixMappingMethod is:
>
>public void startPrefixMapping(String prefix, String uri)
>throws org.xml.sax.SAXException{}
>

That's the bug with xalan. If you check source of AbstractTextSerializer 
[1] you will see how to circumvent this bug.

Vadim

[1] 
http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java?rev=1.4&content-type=text/vnd.viewcvs-markup


>And of course there is a matching endPrefixMapping after endElement.
>
>Is this how it is supposed to work?
>
>
>-=Ivelin=-
>



Re: [XMLForm] Declarative xmlns attribute

Posted by ivelin <iv...@apache.org>.
It is almost embarrassing.
Of course, the solution is very simple and it alleviates Xalan's quirks.
Each of the auto generated elements is within an element already defined in
the source document. So all I had to do is listen to the startPrefixMapping
callback and remember the prefix.

Thanks Stephan !



-=Ivelin=-
----- Original Message -----
From: "Stephan Michels" <st...@apache.org>
To: <co...@xml.apache.org>
Sent: Wednesday, April 23, 2003 1:35 AM
Subject: Re: [XMLForm] Declarative xmlns attribute


>
> On Tue, 22 Apr 2003, ivelin wrote:
>
> >
> > Ok, here is what I tried, but not quite sure if it is correct.
> >
> > AttributesImpl atts;
> > if (attributes == null || attributes.getLength() == 0) {
> > atts = new AttributesImpl();
> > } else {
> > atts = new AttributesImpl(attributes);
> > }
> > startPrefixMapping(NS_PREFIX, NS);
> > atts.addAttribute( "", NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX,
"CDATA",
> > NS);
> > attributes = atts;
> >
> > The gist is that startPrefixMapping is immediately followed by an
explicit
> > attribute.
> > The reason I did this is because without passing an explicit attribute,
> > org.apache.xalan.serialize.SerializerToXML does not output it.
>
> I think this was a bug of Serializer in the past.
>
> > Its startPrefixMappingMethod is:
> >
> > public void startPrefixMapping(String prefix, String uri)
> > throws org.xml.sax.SAXException{}
> >
> > And of course there is a matching endPrefixMapping after endElement.
> >
> > Is this how it is supposed to work?
> >
>
> Yes, at moment, must only remove the code from above. You should
> already have a prefix mapping, if you transform your xform example.
>
> A problem occur, if you use a different prefix than 'xf'. So
> to be sure, you must make a startPrefixMapping in front of
> the startTranformingElement.
>
> Stephan.


Re: [XMLForm] Declarative xmlns attribute

Posted by Stephan Michels <st...@apache.org>.
On Tue, 22 Apr 2003, ivelin wrote:

>
> Ok, here is what I tried, but not quite sure if it is correct.
>
> AttributesImpl atts;
> if (attributes == null || attributes.getLength() == 0) {
> atts = new AttributesImpl();
> } else {
> atts = new AttributesImpl(attributes);
> }
> startPrefixMapping(NS_PREFIX, NS);
> atts.addAttribute( "", NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA",
> NS);
> attributes = atts;
>
> The gist is that startPrefixMapping is immediately followed by an explicit
> attribute.
> The reason I did this is because without passing an explicit attribute,
> org.apache.xalan.serialize.SerializerToXML does not output it.

I think this was a bug of Serializer in the past.

> Its startPrefixMappingMethod is:
>
> public void startPrefixMapping(String prefix, String uri)
> throws org.xml.sax.SAXException{}
>
> And of course there is a matching endPrefixMapping after endElement.
>
> Is this how it is supposed to work?
>

Yes, at moment, must only remove the code from above. You should
already have a prefix mapping, if you transform your xform example.

A problem occur, if you use a different prefix than 'xf'. So
to be sure, you must make a startPrefixMapping in front of
the startTranformingElement.

Stephan.


Re: [XMLForm] Declarative xmlns attribute

Posted by ivelin <iv...@apache.org>.
Ok, here is what I tried, but not quite sure if it is correct.

AttributesImpl atts;
if (attributes == null || attributes.getLength() == 0) {
atts = new AttributesImpl();
} else {
atts = new AttributesImpl(attributes);
}
startPrefixMapping(NS_PREFIX, NS);
atts.addAttribute( "", NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA",
NS);
attributes = atts;

The gist is that startPrefixMapping is immediately followed by an explicit
attribute.
The reason I did this is because without passing an explicit attribute,
org.apache.xalan.serialize.SerializerToXML does not output it.
Its startPrefixMappingMethod is:

public void startPrefixMapping(String prefix, String uri)
throws org.xml.sax.SAXException{}

And of course there is a matching endPrefixMapping after endElement.

Is this how it is supposed to work?


-=Ivelin=-

----- Original Message -----
From: "Vadim Gritsenko" <va...@verizon.net>
To: <co...@xml.apache.org>
Sent: Tuesday, April 22, 2003 8:34 AM
Subject: Re: [XMLForm] Declarative xmlns attribute


> ivelin wrote:
>
> >Good question.
> >startPrefixMap is somewhat confusing.
> >http://lists.xml.org/archives/xml-dev/200108/msg00718.html
> >
>
> Hmm... It's pretty clear to me somehow... This means to me that
> namespace declarations can be moved up/down the XML tree and not
> necesseraly have to stick to the tags they are declared on. Main rule
> is: declare namespace before using it. You can declare it well before or
> right before - this does not matter.
>
>
> >What is the Xalan error text?
> >How would you suggest to patch the code?
> >
>
> We have to use start/endPrefixMappings there, like in all other Cocoon
> components.
>
> Vadim
>
>
> >From: "Stephan Michels" <st...@apache.org>
> >
> >
> >
> >>Hi,
> >>
> >>I have some problems with the following line of the XMLFormTransformer
> >>
> >> atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX,
> >>
> >>
> >"CDATA", NS);
> >
> >
> >>Xalan throw a violation exception, because you shouldn't set xmlns
> >>attribute manually.
> >>
> >>Can we remove this line?
> >>
> >>BTW, I don't see a startPrefixMapping within the transformer.
> >>
> >>Stephan.
> >>
> >>
>


Re: [XMLForm] Declarative xmlns attribute

Posted by Vadim Gritsenko <va...@verizon.net>.
ivelin wrote:

>Good question.
>startPrefixMap is somewhat confusing.
>http://lists.xml.org/archives/xml-dev/200108/msg00718.html
>

Hmm... It's pretty clear to me somehow... This means to me that 
namespace declarations can be moved up/down the XML tree and not 
necesseraly have to stick to the tags they are declared on. Main rule 
is: declare namespace before using it. You can declare it well before or 
right before - this does not matter.


>What is the Xalan error text?
>How would you suggest to patch the code?
>

We have to use start/endPrefixMappings there, like in all other Cocoon 
components.

Vadim


>From: "Stephan Michels" <st...@apache.org>
>
>  
>
>>Hi,
>>
>>I have some problems with the following line of the XMLFormTransformer
>>
>> atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX,
>>    
>>
>"CDATA", NS);
>  
>
>>Xalan throw a violation exception, because you shouldn't set xmlns
>>attribute manually.
>>
>>Can we remove this line?
>>
>>BTW, I don't see a startPrefixMapping within the transformer.
>>
>>Stephan.
>>    
>>



Re: [XMLForm] Declarative xmlns attribute

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2003-04-23 at 10:56, Stephan Michels wrote:
> BTW, I got a NotSuchMethodError from your woody block:
> 
> 10:21:48.060 WARN!! Error for /cocoon/samples/woody/form1
> java.lang.NoSuchMethodError
> 	at
> org.outerj.i18n.JdkI18nSupport.getIntegerFormat(JdkI18nSupport.java:34)
> 	at
> org.apache.cocoon.woody.datatype.typeimpl.LongType.convertToStringLocalized(LongType.java:87)
> 	at
> org.apache.cocoon.woody.datatype.StaticSelectionList$SelectionListItem.generateSaxFragment(StaticSelectionList.java:127)

Oh damn, I'm using a jdk 1.4 method over there. I'll fix it soon.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: [XMLForm] Declarative xmlns attribute

Posted by Stephan Michels <st...@apache.org>.
On 23 Apr 2003, Bruno Dumon wrote:

> On Wed, 2003-04-23 at 08:29, Stephan Michels wrote:
> > On Tue, 22 Apr 2003, ivelin wrote:
> >
> > > Good question.
> > > startPrefixMap is somewhat confusing.
> > > http://lists.xml.org/archives/xml-dev/200108/msg00718.html
> > > What is the Xalan error text?
> >
> > ERROR   10510   [test.test] (): Could not execute test
> >     [junit] org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to
> > create or change an object in a way which is incorrect with regard to
> > namespaces.
> >     [junit] 	at
> > org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:351)
> >     [junit] 	at
> > org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
> >     [junit] 	at
> > org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:130)
> >
> >
>
> I found this a bit suspicious, and after looking at Xalan's DOMBuilder I
> think the problem is over there.
>
> The problem is that SAX and DOM have different conventions as to how
> xmlns attributes should be created.
>
> For SAX it is something like:
> atts.addAttribute( "", "", XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA", NS);
>
> (note that the localname and the uri should be empty strings -- see also
> http://www.saxproject.org/?selected=namespaces)
>
> For DOM it is something like:
> element.setAttributeNS("http://www.w3.org/2000/xmlns/", XMLNS_PREFIX +
> ":" + NS_PREFIX, NS);
>
> (thus with the xmlns namespace explicitely mentioned, see
> http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html)
>
> but Xalan's DOMBuilder does not "translate" between these two
> conventions. So to get no error you could do:
> atts.addAttribute("http://www.w3.org/2000/xmlns/", "", XMLNS_PREFIX +
> ":" + NS_PREFIX, "CDATA", NS);
>
> but this would be against SAX conventions.
>
> I'll see if I can patch this in Xalan.

Thank you.

BTW, I got a NotSuchMethodError from your woody block:

10:21:48.060 WARN!! Error for /cocoon/samples/woody/form1
java.lang.NoSuchMethodError
	at
org.outerj.i18n.JdkI18nSupport.getIntegerFormat(JdkI18nSupport.java:34)
	at
org.apache.cocoon.woody.datatype.typeimpl.LongType.convertToStringLocalized(LongType.java:87)
	at
org.apache.cocoon.woody.datatype.StaticSelectionList$SelectionListItem.generateSaxFragment(StaticSelectionList.java:127)


Re: [XMLForm] Declarative xmlns attribute

Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2003-04-23 at 08:29, Stephan Michels wrote:
> On Tue, 22 Apr 2003, ivelin wrote:
> 
> > Good question.
> > startPrefixMap is somewhat confusing.
> > http://lists.xml.org/archives/xml-dev/200108/msg00718.html
> > What is the Xalan error text?
> 
> ERROR   10510   [test.test] (): Could not execute test
>     [junit] org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to
> create or change an object in a way which is incorrect with regard to
> namespaces.
>     [junit] 	at
> org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:351)
>     [junit] 	at
> org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
>     [junit] 	at
> org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:130)
> 
> 

I found this a bit suspicious, and after looking at Xalan's DOMBuilder I
think the problem is over there.

The problem is that SAX and DOM have different conventions as to how
xmlns attributes should be created.

For SAX it is something like:
atts.addAttribute( "", "", XMLNS_PREFIX + ":" + NS_PREFIX, "CDATA", NS);

(note that the localname and the uri should be empty strings -- see also
http://www.saxproject.org/?selected=namespaces)

For DOM it is something like:
element.setAttributeNS("http://www.w3.org/2000/xmlns/", XMLNS_PREFIX +
":" + NS_PREFIX, NS);

(thus with the xmlns namespace explicitely mentioned, see
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html)

but Xalan's DOMBuilder does not "translate" between these two
conventions. So to get no error you could do:
atts.addAttribute("http://www.w3.org/2000/xmlns/", "", XMLNS_PREFIX +
":" + NS_PREFIX, "CDATA", NS);

but this would be against SAX conventions.

I'll see if I can patch this in Xalan.

> BTW, I must say writing testcases helps me a lot finding hidden
> bugs. All I can say is write testcases, people!

With the basic infrastructure in place, the barrier for doing so has
lowered a lot. Good work!

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Re: [XMLForm] Declarative xmlns attribute

Posted by Stephan Michels <st...@apache.org>.
On Tue, 22 Apr 2003, ivelin wrote:

> Good question.
> startPrefixMap is somewhat confusing.
> http://lists.xml.org/archives/xml-dev/200108/msg00718.html
> What is the Xalan error text?

ERROR   10510   [test.test] (): Could not execute test
    [junit] org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to
create or change an object in a way which is incorrect with regard to
namespaces.
    [junit] 	at
org.apache.xml.utils.DOMBuilder.startElement(DOMBuilder.java:351)
    [junit] 	at
org.apache.xalan.transformer.TransformerIdentityImpl.startElement(TransformerIdentityImpl.java:1020)
    [junit] 	at
org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:130)


You can run the tests by yourself (> ant test).

BTW, I must say writing testcases helps me a lot finding hidden
bugs. All I can say is write testcases, people!

Stephan.


Re: [XMLForm] Declarative xmlns attribute

Posted by ivelin <iv...@apache.org>.
Good question.
startPrefixMap is somewhat confusing.
http://lists.xml.org/archives/xml-dev/200108/msg00718.html
What is the Xalan error text?
How would you suggest to patch the code?

-=Ivelin=-

----- Original Message -----
From: "Stephan Michels" <st...@apache.org>
To: "cocoon-dev" <co...@xml.apache.org>
Sent: Tuesday, April 22, 2003 3:45 AM
Subject: [XMLForm] Declarative xmlns attribute


> Hi,
>
> I have some problems with the following line of the XMLFormTransformer
>
>  atts.addAttribute( null, NS_PREFIX, XMLNS_PREFIX + ":" + NS_PREFIX,
"CDATA", NS);
>
> Xalan throw a violation exception, because you shouldn't set xmlns
> attribute manually.
>
> Can we remove this line?
>
> BTW, I don't see a startPrefixMapping within the transformer.
>
> Stephan.
>
> _______________________________________________________________________
>          Stephan Michels               EMail: stephan@apache.org
>          ICQ: 115535699                Tel: +49-030-314-21583
> ----+----|----+----|----+----|----+----|----+----|----+----|----+----|-|
>