473,657 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add root node to xmltextwriter

Hi,

I am retriving data from sql server using the xml raw clause and an
xmltextwriter.

this is working out fine except the xml raw clause does not put a root node
on the xml that is returned from sql server and subsequently an xmldocument
can't be created from the xmltextwriter as there is no root element.

however if the xml raw query returns only a single row then there is a root
element and everything works just fine.

my question is how do I attach a root element to an xmltextwriter when it
does not contain one??

many thanks in advance.

cheers

martin.

SqlConnection conn = new SqlConnection(
"server=.;uid=p ubsUser;passwor d=pubsUser;data base=pubs");

SqlCommand cmd = new SqlCommand(
"select top 1 * from authors for xml raw", //<==== does not work
when "top 1" is removed as there is no root node
conn);

conn.Open();

XmlTextReader rdr;
rdr = (XmlTextReader) cmd.ExecuteXmlR eader();
XmlDocument xml = new XmlDocument();
xml.Load(rdr); <============== ========will fail if there is not a root
node...
xml.Save(Consol e.Out);

Nov 23 '05 #1
0 1286

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

Similar topics

5
6153
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to insert in the front. My code is give below. Is it possible to do without using XMLDOcument? Dim masterDoc As String = Request.PhysicalApplicationPath & "PageViews.xml" Dim writer As XmlTextWriter = Nothing
4
11794
by: Sebastien Tardif | last post by:
Subject: XmlSerializer.Deserialize complain when root declare the namespace If I do XmlSerializer.Deserialize( myString ) and myString is: String myString = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocumentResponse ><documentSize xmlns=\"urn:webservices.docharbor.com\">23</documentSize></DocumentResponse>"; It's working
1
2449
by: Jonathan Taylor | last post by:
I have a large XML file, that is too large to read in to XmlDocument. I need to append data to this XML file without creating a new file, since I don't want to have two copies of the large file on the server. I've not seen any example that works so far, even with google. Can anyone help ?
15
4149
by: Stig Brautaset | last post by:
Hi group, I'm playing with a little generic linked list/stack library, and have a little problem with the interface of the pop() function. If I used a struct like this it would be simple: struct node { struct node *next; void *data; };
0
1092
by: Martin | last post by:
Hi, I am retriving data from sql server using the xml raw clause and an xmltextwriter. this is working out fine except the xml raw clause does not put a root node on the xml that is returned from sql server and subsequently an xmldocument can't be created from the xmltextwriter as there is no root element. however if the xml raw query returns only a single row then there is a root
3
35061
by: lisa.bogart | last post by:
I am getting a "Root element is missing" error when I try to load a stream into and XmlDocument. Can anyone help me with what I am doing wrong??? Dim xmlTextWriter As XmlTextWriter = Nothing Dim objFile As FileStream = Nothing objStream = New MemoryStream()
2
2513
by: ershad | last post by:
Hello, I want to add a namespaces to the root element in a XML-message using the XmlTextWriter class: My XML-stream looks like this: <?xml version="1.0" encoding="us-ascii" standalone="yes"?> <root> <session name="All about XML"> <slides>
1
2113
by: ershad | last post by:
Hello, I want to add a namespaces to the root element in a XML-message using the XmlTextWriter class: My XML-stream looks like this: <?xml version="1.0" encoding="us-ascii" standalone="yes"?> <root> <session name="All about XML"> <slides>
2
4702
by: danimian | last post by:
Hello, first i am creating xml file if file does not exist. String myFile = "C:\myxmlfile.xml"; if (!File.Exists(myFile)) { using (FileStream conStream = new FileStream(myFile, FileMode.Create, FileAccess.Write)) { XmlWriter conWriter = new XmlTextWriter(conStream, Encoding.UTF8); conWriter.WriteStartDocument(); conWriter.WriteStartElement("myrootnode"); conWriter.WriteStartElement("myfirstnode"); conWriter.WriteEndDocument();
0
8821
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...
1
8502
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8602
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
7316
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...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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();...
1
2726
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
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.