cburgmer/xmlserializer — pull request #6 by kevinoid (2014-09-26 16:04:35+00:00)
Title: Always output an xmlns attribute on namespace changes

Hi @cburgmer, thanks for your work on this project. I have been using it as part of rasterizeHTML and find it very useful with just a few issues. This PR should address the primary one I'm experiencing:

Currently xmlserializer only outputs an `xmlns` attribute when `xmlns` appears in the `attributes` collection or the element is ``. Unfortunately, this does not work for elements which are created dynamically using `createElementNS`. It's likely also an issue for documents where an XML parser is used (e.g. documents with an XML media type in browsers), but I have not tested it.

This pull request additionally outputs an `xmlns` attribute whenever the namespace of an element does not match the namespace of its parent (or when it doesn't have a parent from which to inherit a
namespace). In all such cases the `xmlns` attribute is required to preserve the namespace of the element.

A proper solution for handling namespaces in XML would also need to consider the prefix->namespace mapping on each element and output appropriate prefixed `xmlns` attributes for each mapping change from the parent element. However, since prefixes aren't currently supported (AFAICT), I've left it out of this PR.

Thanks,
Kevin