The atom formatter seems to specify
namespaces inline multiple times.
Is there any way to easily consolidate
these. The example below shows
namespaces specified three times for
each property. This is horrible.
The easiest way to produce this more compact format is to apply the following XSLT transformation on your XML document:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()[not(self::*)]|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}" namespace="{namespace-uri()}">
<xsl:copy-of select="descendant::*/namespace::*"/>
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
For example, when applied on the following XML document (based on your question):
<t xmlns="http://a9.com/-/opensearch/extensions/property/1.0/">
<property p3:name="firstname"
xmlns:p3="http://a9.com/-/opensearch/extensions/property/1.0/"
xmlns="http://a9.com/-/opensearch/extensions/property/1.0/"
>Drikie</property>
</t>
the wanted result is produced:
<t
xmlns="http://a9.com/-/opensearch/extensions/property/1.0/"
xmlns:p3="http://a9.com/-/opensearch/extensions/property/1.0/">
<property p3:name="firstname">Drikie</property>
</t>
Do note:
A namespace declaration cannot be promoted further above an element that has a declaration that binds the same prefix to another namespace.
Promoting a namespace declaration to an ancestor element may increase the size of the parsed XML document, because all namespace nodes are propagated down to all descendent nodes, some of which may not need at all that namespace.