all groups > dotnet xml > january 2007 >
You're in the

dotnet xml

group:

Reformatting xml


Reformatting xml Riccardo
1/3/2007 3:09:35 AM
dotnet xml:
Hello,

I have an xml sample string like this:
<?xml version="1.0" encoding="ISO-8859-1"?><catalog><cd><title>Empire
Burlesque</title><artist>Bob
Dylan</artist><country>USA</country><company>Columbia</company><price>10.90</price><year>1985</year></cd></catalog>

and I need to obtaing a new reformatted version like this for a better
display in a richtextbox control:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
How can I do that?
Maybe I can do that with xsl or a c# recoursive procedure but what's
better solution?

Thanks
Re: Reformatting xml Riccardo
1/3/2007 7:07:27 AM
Martin Honnen ha scritto:
[quoted text, click to view]

great, thank you.
Re: Reformatting xml Martin Honnen
1/3/2007 2:21:17 PM
[quoted text, click to view]

Apply an XSLT stylesheet like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

With .NET 1.x you should be using System.Xml.Xsl.XslTransform, with .NET
2 and 3 System.Xml.Xsl.XslCompiledTransform to run an XSLT transformation.




--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button