You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Michael Glavassevich (JIRA)" <xe...@xml.apache.org> on 2005/03/29 00:20:32 UTC

[jira] Commented: (XERCESJ-1050) XMLSerializer outputs unqualified attributes when NS URI is same as parent element's NS URI

     [ http://issues.apache.org/jira/browse/XERCESJ-1050?page=comments#action_61680 ]
     
Michael Glavassevich commented on XERCESJ-1050:
-----------------------------------------------

The SAX serialization code currently has no active maintainers, so it isn't likely that this will be fixed in the near future, unless someone (or yourself) provides a patch. In a future release (perhaps Xerces 2.7.0) we plan to move to Xalan's serialization code, at which point XMLSerializer [1] would likely become deprecated. The alternative is to use JAXP's TransformerHandler [2] for SAX serializer.

[1] http://xml.apache.org/xerces2-j/faq-general.html#faq-5
[2]http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/sax/TransformerHandler.html

> XMLSerializer outputs unqualified attributes when NS URI is same as parent element's NS URI
> -------------------------------------------------------------------------------------------
>
>          Key: XERCESJ-1050
>          URL: http://issues.apache.org/jira/browse/XERCESJ-1050
>      Project: Xerces2-J
>         Type: Bug
>   Components: Serialization, SAX
>  Environment: Linux 2.6.8-24.10-default
> java version 1.4.2_06
>     Reporter: Manos Batsis

>
> XMLSerializer creates unqualified attributes when those have the same namespace URI as their parent element. A workaround is to also provide a QName, but that should not be neccessary (plus it's error prone). The following produces three attributes; the second one should be qualified but is not.
> OutputFormat format = new OutputFormat("xml", "UTF-8", true);
> format.setIndenting(true);
> XMLSerializer xmlserializer = new XMLSerializer();
> xmlserializer.setOutputFormat(format);
> xmlserializer.setNamespaces(true);
> xmlserializer.setOutputByteStream(System.out);
> xmlserializer.startDocument();
> xmlserializer.startPrefixMapping("test1", "http://geekologue.com/test1");
> xmlserializer.startPrefixMapping("test2", "http://geekologue.com/test2");
>         
> AttributesImpl resourceRefAtts = new AttributesImpl();
> resourceRefAtts.addAttribute("http://geekologue.com/test1", "qualified", "", "CDATA", "this attribute is qualified as it's NS URI is different from the parent element NS URI");
> resourceRefAtts.addAttribute("http://geekologue.com/test2", "unqualified", "", "CDATA",  "this attribute is unqualified (Bug?) as it's NS URI is the same as the parent element NS URI");
> resourceRefAtts.addAttribute("http://geekologue.com/test2", "unqualified-qualified", "test2:unqualified-qualified", "CDATA",  "this attribute is qualified although it's NS URI is the same as the parent element NS URI, because we also provide a QName (but we shouldn't)");
>         
>         
> xmlserializer.startElement("http://geekologue.com/test2", "element", null, resourceRefAtts);
> xmlserializer.endElement("http://geekologue.com/test2", "element", null);
>         
> xmlserializer.endPrefixMapping("test1");
> xmlserializer.endPrefixMapping("test2");
>         
> xmlserializer.endDocument();

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org