473,890 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert XmlReader to string

I wish to receive some data from SqlServer as XML and write out result
to as a string.

Eg: cmd = new SqlCommand( "select * from blah for xml auto", con );

XmlReader result = cmd.ExecuteXmlR eader( );

Console.Writeln ( result.ToString ( ) );

This XML is meant to be the input for an XSLT transform so I'm
interested in seeing the XML in a form similar to <row col1='blah'
col2='blah' />. The XML comes back ok, but I'm not sure how to convert
the XmlReader into a String in an efficient manner.

One way I know would be to load it into a dataset and then write out
as XML and another way would be to serialize / deserialize from an
object, but surely there is a simple way of converting the XmlReader
into a String.

Cheers Dave
Nov 16 '05 #1
2 17215
muesliflakes <mu**********@y ahoo.com.au> wrote:
I wish to receive some data from SqlServer as XML and write out result
to as a string.

Eg: cmd = new SqlCommand( "select * from blah for xml auto", con );

XmlReader result = cmd.ExecuteXmlR eader( );

Console.Writeln ( result.ToString ( ) );

This XML is meant to be the input for an XSLT transform so I'm
interested in seeing the XML in a form similar to <row col1='blah'
col2='blah' />. The XML comes back ok, but I'm not sure how to convert
the XmlReader into a String in an efficient manner.

One way I know would be to load it into a dataset and then write out
as XML and another way would be to serialize / deserialize from an
object, but surely there is a simple way of converting the XmlReader
into a String.


The easiest thing is to read the whole document in using
XmlDocument.Loa d(XmlReader) and then either write it out again using an
XmlWriter writing to a StringWriter, or something similar. (I haven't
tried calling OuterXml on an XmlDocument - that might do it for you in
a very straightforward way.)

Of course, this is a somewhat inefficient way of doing things. An
alternative is to have an XmlWriter writing to a StringWriter and use
XmlWriter.Write Node (XmlReader, bool). I can't say I've tried that
either, to be honest - but it's worth having a go.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
d c
I would love to use the XmlDocument class but the problem is that this
class requires the XmlReader to return a well formed document.

My query which is to get the structure of a table:

select * from information_sch ema.columns where table_name = 'MtFeedback'
for xml auto

Does not return a well formed document, it only returns an XML fragment.

No Root Element:
<information_sc hema.columns TABLE_CATALOG=" Mt" TABLE_SCHEMA="d bo"
TABLE_NAME="MtF eedback" COLUMN_NAME="Mt FeedbackIy" ORDINAL_POSITIO N="1"
IS_NULLABLE="No " DATA_TYPE="int" NUMERIC_PRECISI ON="10"
NUMERIC_PRECISI ON_RADIX="10" NUMERIC_SCALE=" 0"/>

<information_sc hema.columns TABLE_CATALOG=" Mt" TABLE_SCHEMA="d bo"
TABLE_NAME="MtF eedback" COLUMN_NAME="Ti tle" ORDINAL_POSITIO N="2"
IS_NULLABLE="YE S" DATA_TYPE="varc har" CHARACTER_MAXIM UM_LENGTH="50"
CHARACTER_OCTET _LENGTH="50" CHARACTER_SET_N AME="iso_1"
COLLATION_NAME= "Latin1_General _CI_AS"/>

etc...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

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

Similar topics

3
10303
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
4
17693
by: Ken Varn | last post by:
I have an unknown numeric Type object passed into a function. I want to run a conversion on a string to convert the string to that Type object and return an object of that type. Is there some way to do a generic cast or conversion on the type? Here is sort of what I want to do: object MyFunc(Type T, String Str) { object o;
1
6243
by: dongxm | last post by:
XslTransform xslt = new XslTransform(); xslt.Load(myXmlReader) the myXmlReader is a XmlReader,but i have String of xsl file's content... how to do,String convert XmlReader? thanks
15
10848
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
5
22811
by: Ken Sturgeon | last post by:
Using VB.NET in VS2005, assume that you have a RegEx that matches a specific html tag; for instance "<title>.*?</title>" that returns a match "<title>SomeTitleHere</title>" and you want to convert that string into an xmlNode so you can just grab the InnerHTML... how would you go about converting it to an xmlNode? My thanks to all respondents in advance for your help. Ken
3
9211
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
1
369
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number? ----------------------------------------------------------------------- Javascript variables are loosely typed: the conversion between a string and a number happens automatically. Since plus (+) is also used as in string concatenation, « '1' + 1 » is equal to « '11' »: the String deciding...
2
2241
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number? ----------------------------------------------------------------------- Javascript variables are loosely typed: the conversion between a string and a number happens automatically. Since plus (+) is also used as in string concatenation, ` '1' + 1 ` is equal to ` '11' `: the String deciding...
12
4990
by: aatif | last post by:
I want to convert a string of hex characters (2 hex chars = 1 byte), to ASCII. Hex chars include zeros (0x00) as well, which I want to include in ASCII string. hex string: 5000005355.... ASCII: P<null><null>SU... I can do it and the string length also includes nulls but when I concatenate other string, it doesn't show as its part. string HexValue = "500000535500";
0
9979
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
11234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10828
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
10467
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
9638
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7171
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
6052
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
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
3282
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.