471,594 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Help removing xmlns from my xml data (string)

Hello,

I have a string variable that contains XML data with many different
namespaces. I like to remove all the namespaces from my XML (clean the XML).
What's the quickest way to do this?

Ex.
<report xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" > change to
<report>

Thanks
Maz.
Nov 12 '05 #1
1 1896


Maziar Aflatoun wrote:

I have a string variable that contains XML data with many different
namespaces. I like to remove all the namespaces from my XML (clean the XML).
What's the quickest way to do this?

Ex.
<report xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" > change to
<report>


That is easy as the namespace declared is not used.
What do you want to get from
<pf:report xmlns:pf="http://example.com/2005/ns1" />
?

As for removing namespaces XSLT is certainly a tool that can do it so
within .NET you could use XslTransform to transform the XML with an XSLT
stylesheet that removes namespaces e.g. uses
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Simon Hart | last post: by
reply views Thread by =?Utf-8?B?ZWQ=?= | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.