473,748 Members | 5,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4474
"sp" <sp@discussions .microsoft.com> wrote in message news:AD******** *************** ***********@mic rosoft.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.Map Path( ".\" + yourXsltFilenam e));
xsl.Transform( xpathDoc.Create Navigator( ), null, new StringWriter( buf));
string strContainingXm l = 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.Tex t = strContainingXm l.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******** *************** ***********@mic rosoft.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.Map Path( ".\" + yourXsltFilenam e));
xsl.Transform( xpathDoc.Create Navigator( ), null, new StringWriter( buf));
string strContainingXm l = 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.Tex t = strContainingXm l.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
2902
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 knew db's and gave me long list of things to do with that particular database, first thing being that particular conversion. Truth is that I don't know a first thing about db's, let alone using mysql... I downloaded mysql form www.mysql.com and...
3
22462
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? If you know it you can send me a message to ckjonny5@hotmail.com Thanks at all. Jonny
4
1880
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
2265
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 will work with a variable mutl- row, 5 column datatable where the users select items. Anyone have any suggestions on where to start? Or changes in the current code that might be made.
1
4394
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? If you know it you can send me a message to ckjonny5@hotmail.com Thanks at all. Jonny
3
6107
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 tell how to do it? ------ Thanks
8
2236
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 lossless fashion to a more modern format. The database has more than 65K rows, so converting it to be an Excel spreadsheet, would, AFAIK, not be an option. It would seem that MS Works can export the database as a DBF format database, though I...
3
2397
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), and - trailing zeroes are kept. This means I need it to be converted using the scientific notation if the number is greater than a certain value etc., not just a simple "this number of digits (or more if needed) before the decimal point
2
11182
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") pArray is a variant array containing a date string at pArray(4, iRecord) in the format "yyyy/mm/dd"
3
7159
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 to autoformat the contents of text entries in a GUI. For numbers, I'm converting the text representation to the appropriate type (using atoi, atof, ...) and converting the result back to text with the correct format (using sprintf). But this does...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.