"sp" <sp@discussions.microsoft.com> wrote in message news:AD**********************************@microsof t.com...
I need to convert xml that we get from sqlserver For xml auto to my own
xml format using asp.net classes.
Any ideas and suggestions would be appreciated.
For Xml will usually return you an XML fragment, instead of an XML document
(i.e., there will be multiple root elements which are illegal in an XmlDocument
object). For example, you may receive,
<row>
<col1>one</col1>
<col2>two</col2>
</row>
<row>
<col1>one</col1>
<col2>two</col2>
</row>
To make this into an XML document you need to create a single root element
that contains this XML, so that it looks like this,
<data>
<row>
<col1>one</col1>
<col2>two</col2>
</row>
<row>
<col1>one</col1>
<col2>two</col2>
</row>
</data>
In this form you can load it into an XPathDocument, and then using the
CreateNavigator( ) method to get an XPathNavigator, pass that navigator
to an XslTransform that you've loaded with an XSLT stylesheet. The
XSLT stylesheet you'll write describes how to transform from the XML
format above into your desired XML format.
StringBuilder buf = new StringBuilder( )
XslTransform xsl = new XslTransform( );
xsl.Load( ServerUtils.MapPath( ".\" + yourXsltFilename));
xsl.Transform( xpathDoc.CreateNavigator( ), null, new StringWriter( buf));
string strContainingXml = buf.ToString( );
How do you intend to display this XML in ASP.NET?
One thing to be aware of is that if you put the XML as a string into a
Label's Text, for example, the angle brackets will be interpreted by
the browser as HTML. To actually display literal angle brackets,
you need to do a Replace( ) of '<' to "<" instead.
this.Label1.Text = strContainingXml.Replace("&","&").Replace( "<", "<");
Derek Harmon