473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Converting xml to another format of xml using ASP.NET

sp
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
sp
Nov 12 '05 #1
2 4432
"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 "&lt;" instead.

this.Label1.Text = strContainingXml.Replace("&","&amp;").Replace( "<", "&lt;");
Derek Harmon
Nov 12 '05 #2
sp
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

"Derek Harmon" wrote:
"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

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I...
3
by: Jonny Au | last post by:
Hi everyone, I have a problem about email message format converting. I want to write a program in VB.NET to convert the EML format email message to MSG format, does anyone knows how to do it?...
4
by: (Pete Cresswell) | last post by:
I've got everything in 2000 format right now, but it's now clear that all of the clients will be running 2003. Is there any advantage in converting? -- PeteCresswell
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
1
by: Jonny Au | last post by:
Hi everyone, I have a problem about email message format converting. I want to write a program in VB.NET to convert the EML format email message to MSG format, does anyone knows how to do it?...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
8
by: Michael B. Trausch | last post by:
I was wondering if anyone has had any experience with this. Someone I know is trying to move away from Microsoft Works, and I am trying to look into a solution that would convert their data in a...
3
by: nvx | last post by:
Hi, I'm looking for a simple way to convert a Double to a String exactly the .ToString() does, except these two differences: - the number of decimals is given (rounding is applied if necessary),...
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.