all groups > dotnet xml > november 2004 >
You're in the

dotnet xml

group:

Converting xml to another format of xml using ASP.NET


Converting xml to another format of xml using ASP.NET sp
11/4/2004 12:05:03 PM
dotnet xml: Hello Everybody,

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.
Thanks in Advance
Re: Converting xml to another format of xml using ASP.NET Derek Harmon
11/4/2004 10:42:30 PM
[quoted text, click to view]

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 "&lt;" instead.

this.Label1.Text = strContainingXml.Replace("&","&amp;").Replace( "<", "&lt;");


Derek Harmon

Re: Converting xml to another format of xml using ASP.NET sp
11/10/2004 9:24:02 AM
Hi MR.Harmon,
Thanks for taking time to anwer my question. My another question is How
can i add root element for For xml auto clause

Thanks
sp

[quoted text, click to view]
AddThis Social Bookmark Button