When constructing an XML document programmatically, the namespaces in use and prefixes may be inconsistent. For example, the results of merging cloned nodes from different sources may end up with conflicting prefix to namespace mappings. These conflicts must be detected and the prefixes adjusted.
The current implementation allows multiple namespace attributes for the same prefix which results in an XML parsing error for any receiving application.
Could you please attach a test case fixing which would be the purpose of this bug? We have quite a few bugs about namespace serialization already, and it's difficult to track them without explicitly distinct test cases.
Created attachment 205019 [details]
An example of inconsistent handling of namespaces for attributes
Here is the missing attachment that I thought I filed with the original bug.
The test does:
1. Creates two attributes with different namespaces but the same prefix.
2. Redefined a common prefix (xlink).
The outcome right now is:
1. The "p" prefix is declared twice with to different namespace URIs.
2. A extra xmlns:xlink attribute that maps the the XLink namespace URI is added.
Of course, that won't parser properly on the way back in.
Bug 19121 has a patch up that fixes this bug too. I incorporated the testcase in it.
Committed r154779: <http://trac.webkit.org/changeset/154779>.