[ 
https://issues.apache.org/jira/browse/XERCESJ-793?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Elliotte Rusty Harold updated XERCESJ-793:
------------------------------------------
    Description: 
Hi there,

when running the code:
{{
  StringWriter writer = new StringWriter();
  XMLSerializer serializer = new XMLSerializer(writer, null);
  serializer.setNamespaces(true);
  serializer.startDocument();
  AttributesImpl attrs = new AttributesImpl();
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns1", "xmlns:ns1", "CDATA", "http://url";);
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns2", "xmlns:ns2", "CDATA", "http://url";);
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns3", "xmlns:ns3", "CDATA", "http://otherurl";
);
  attrs.addAttribute("http://url";, "attr1", "ns1:attr1", "CDATA", "value1");
  attrs.addAttribute("http://url";, "attr2", "ns2:attr2", "CDATA", "value2");
  serializer.startElement(null, "root", "root", attrs);
  serializer.endElement(null, "root", "root");
  serializer.endDocument();
  System.out.println("writer.toString() = \n" + writer.toString());}}

I get as a result:
{{  writer.toString() =
  <?xml version="1.0"?>
  <root ns1:attr1="value1" ns2:attr2="value2" xmlns:ns3="http://otherurl"; 
xmlns:ns1="http://url"/>}}

In words, the second namespace declaration for http://url is not serialized, 
and as a result the output is not namespace wellformed.

Tested against Xerces 2.4 and 2.5.

Work-arounds (not involving changing the input) would be very welcome (DOM 
serialization does not seem to have this problem, but is not an option for us).

  was:
Hi there,

when running the code:

  StringWriter writer = new StringWriter();
  XMLSerializer serializer = new XMLSerializer(writer, null);
  serializer.setNamespaces(true);
  serializer.startDocument();
  AttributesImpl attrs = new AttributesImpl();
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns1", "xmlns:ns1", "CDATA", "http://url";);
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns2", "xmlns:ns2", "CDATA", "http://url";);
  attrs.addAttribute
("http://www.w3.org/2000/xmlns/";, "ns3", "xmlns:ns3", "CDATA", "http://otherurl";
);
  attrs.addAttribute("http://url";, "attr1", "ns1:attr1", "CDATA", "value1");
  attrs.addAttribute("http://url";, "attr2", "ns2:attr2", "CDATA", "value2");
  serializer.startElement(null, "root", "root", attrs);
  serializer.endElement(null, "root", "root");
  serializer.endDocument();
  System.out.println("writer.toString() = \n" + writer.toString());

I get as a result:
  writer.toString() =
  <?xml version="1.0"?>
  <root ns1:attr1="value1" ns2:attr2="value2" xmlns:ns3="http://otherurl"; 
xmlns:ns1="http://url"/>

In words, the second namespace declaration for http://url is not serialized, 
and as a result the output is not namespace wellformed.

Tested against Xerces 2.4 and 2.5.

Work-arounds (not involving changing the input) would be very welcome (DOM 
serialization does not seem to have this problem, but is not an option for us).


> When using serializer in 'content handler' mode, duplicate namespace 
> delcarations are missed
> --------------------------------------------------------------------------------------------
>
>                 Key: XERCESJ-793
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-793
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: Serialization
>    Affects Versions: 2.5.0
>         Environment: Operating System: Windows NT/2K
> Platform: PC
>            Reporter: Sander Bos
>
> Hi there,
> when running the code:
> {{
>   StringWriter writer = new StringWriter();
>   XMLSerializer serializer = new XMLSerializer(writer, null);
>   serializer.setNamespaces(true);
>   serializer.startDocument();
>   AttributesImpl attrs = new AttributesImpl();
>   attrs.addAttribute
> ("http://www.w3.org/2000/xmlns/";, "ns1", "xmlns:ns1", "CDATA", "http://url";);
>   attrs.addAttribute
> ("http://www.w3.org/2000/xmlns/";, "ns2", "xmlns:ns2", "CDATA", "http://url";);
>   attrs.addAttribute
> ("http://www.w3.org/2000/xmlns/";, "ns3", "xmlns:ns3", "CDATA", 
> "http://otherurl";
> );
>   attrs.addAttribute("http://url";, "attr1", "ns1:attr1", "CDATA", "value1");
>   attrs.addAttribute("http://url";, "attr2", "ns2:attr2", "CDATA", "value2");
>   serializer.startElement(null, "root", "root", attrs);
>   serializer.endElement(null, "root", "root");
>   serializer.endDocument();
>   System.out.println("writer.toString() = \n" + writer.toString());}}
> I get as a result:
> {{  writer.toString() =
>   <?xml version="1.0"?>
>   <root ns1:attr1="value1" ns2:attr2="value2" xmlns:ns3="http://otherurl"; 
> xmlns:ns1="http://url"/>}}
> In words, the second namespace declaration for http://url is not serialized, 
> and as a result the output is not namespace wellformed.
> Tested against Xerces 2.4 and 2.5.
> Work-arounds (not involving changing the input) would be very welcome (DOM 
> serialization does not seem to have this problem, but is not an option for 
> us).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to