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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to