Hi,

the way I read the SAX specification, the qName (or raw name) of elements that
is passed to the callback methods is of purely informal character and does not
necessarily contain the full (raw) element name. However, C2's serialization
to XML results in the qName being used to name the output elements. This is
due to the missing or incomplete namespace support in the SerializerToXML from
Xalan which is used.

AbstractTextSerializer already contains code to work around Xalan problems, so
it could fix this problem as well, although fixing it comes at the cost of 2
hashtable lookups and string concatenations per element. If you agree that
this should be done, the following patch will do the job.

Joerg Henne
Index: org/apache/cocoon/serialization/AbstractTextSerializer.java
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.2
diff -r1.2 AbstractTextSerializer.java
13a14,15
> import java.util.Map;
> import java.util.HashMap;
59a62,68
>      * Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
>      * serializer.
>      */
>     private Map uriToPrefixMap = new HashMap();
>     private Map prefixToUriMap = new HashMap();
> 
>     /**
153a163,164
>         this.uriToPrefixMap.clear();
>         this.prefixToUriMap.clear();
177a189,193
>         // store mappings for xalan-bug-workaround.
>         // append the prefix colon now, in order to save concatenations later.
>         this.uriToPrefixMap.put(uri, prefix + ":");
>         this.prefixToUriMap.put(prefix, uri);
>         
181a198,215
>      * End the scope of a prefix-URI mapping.
>      *
>      * @param prefix The prefix that was being mapping.
>      */
>     public void endPrefixMapping(String prefix)
>       throws SAXException {
>         // remove mappings for xalan-bug-workaround.
>         // Unfortunately, we'return not passed the uri, but the prefix here,
>         // so we need to maintain maps in both directions.
>         if(this.prefixToUriMap.containsKey(prefix)) {
>           this.uriToPrefixMap.remove((String) this.prefixToUriMap.get(prefix));
>           this.prefixToUriMap.remove(prefix);
>         }
>         
>         super.endPrefixMapping(prefix);
>     }
> 
>     /**
189c223,227
< 
---
>         
>         // try to restore the qName. The map already contains the colon
>         if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
>           eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
>         
248a287,299
>     }
> 
>     /**
>      * Receive notification of the end of an element.
>      * Try to restore the element qName.
>      */
>     public void endElement(String eltUri, String eltLocalName, String eltQName)
>     throws SAXException {
>         // try to restore the qName. The map already contains the colon
>         if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
>           eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
>         
>         super.endElement(eltUri, eltLocalName, eltQName);
 
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to