473,785 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Declaration is missing when I convert a dataset to xml

This is my first time trying to take the results of a query that
reside in a Dataset and convert the dataset into an xml file.
Everything works great, except that my resulting XML file is missing
the xml declaration (the first line): <?xml version="1.0"
encoding="iso-8859-1"?>

Below is an example of the code I am using:
dataset.Namespa ce = "RatesXML"
Dim xmlFilename As String = "myXmlDocument. xml"
Dim fsWriteXml As New System.IO.FileS tream(xmlFilena me,
System.IO.FileM ode.Create)
Dim xmlWriter As New
System.Xml.XmlT extWriter(fsWri teXml,System.Te xt.Encoding.Uni code)
dataset.WriteXm l(xmlWriter)
fsWriteXml.Clos e()
dataset.Dispose ()
Dim newDataSet As New DataSet("New DataSet")
Dim fsReadXml As New System.IO.FileS tream(xmlFilena me,
System.IO.FileM ode.Open)
Dim myXmlReader As New System.Xml.XmlT extReader(fsRea dXml)
newDataSet.Read Xml(myXmlReader )
myXmlReader.Clo se()

I get back my xml file with all the children and elements as expected,
except the declaration is not present. How can I get the xml
declaration to appear in the new xml file? I assume it is an option
that I can add. Thank you.
Nov 12 '05 #1
2 4595
Todd wrote:
This is my first time trying to take the results of a query that
reside in a Dataset and convert the dataset into an xml file.
Everything works great, except that my resulting XML file is missing
the xml declaration (the first line): <?xml version="1.0"
encoding="iso-8859-1"?>

Below is an example of the code I am using:
dataset.Namespa ce = "RatesXML"
Dim xmlFilename As String = "myXmlDocument. xml"
Dim fsWriteXml As New System.IO.FileS tream(xmlFilena me,
System.IO.FileM ode.Create)
Dim xmlWriter As New
System.Xml.XmlT extWriter(fsWri teXml,System.Te xt.Encoding.Uni code)


So if you want iso encoding, why do you write it as Unicode? Write it in
ISO-8859-1 encoding.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Shane Cook
1 New Member
private void WriteXmlToFile( DataSet thisDataSet)
{
if (thisDataSet == null) { return; }

// Create a file name to write to.
string filename = "XmlDoc.xml ";

// Create the FileStream to write with.
System.IO.FileS tream stream = new System.IO.FileS tream
(filename, System.IO.FileM ode.Create);

// Create an XmlTextWriter with the fileStream.
System.Xml.XmlT extWriter xmlWriter =
new System.Xml.XmlT extWriter(strea m,
System.Text.Enc oding.Unicode);

// Write Declarative with 'Standalone' attribute set to 'yes'.
xmlWriter.Write StartDocument(t rue);

// Write to the file with the WriteXml method.
thisDataSet.Wri teXml(xmlWriter );
xmlWriter.Close ();
}

Shane Cook
Jun 29 '06 #3

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

Similar topics

6
8348
by: David B. Bitton | last post by:
I am having a problem deserializing XML when the root node is missing a namespace declaration. My Type has an XmlTypeAttribute with a namespace defined. If I attempt to deserialize the XML, I get the dreaded <elementname xmlns=''> was not expected exception. If I comment out the XmlTypeAttribute, it works just fine. Just so you know, when I instantiate an instance of an XmlSerializer, I pass a default namespace to the ctor. ...
3
1777
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef System::Byte ByteArray __gc;
2
1574
by: Andrew | last post by:
Hey all, Have a strange one here, and being still fairly new to .NET isn't helping me understand it. I am having a problem where a DataReader doesn't return all the rows when I try to use a method from a separate class file that returns a DataReader, where when I code the DataReader in the .aspx file it does. Below are the details and code of what I am runnign into. I appreciate any help/insight you can provide.
0
1535
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway when the user selects the first dropdownlist the dropdownselected_indexchanged is firring but when the user chagnes the second dropdownlist its not firing. aahh! if the user selects any of both dropdownlist the datagrid stays with only one row?...
2
1836
by: Jeff Brown | last post by:
OK i have came to the conclusion that since this app will be run on multiple computers that loading a complete database and then updating on exit is a moot point. I have tried several ideas submitted, but i am unable to get one of them to work completely. Here is the code i had before i realized that when i filled the dataset in the form load procedure that it would "ruin, replace, mess up" the dataset named the same thing on the other form....
3
1795
by: dekern | last post by:
Good afternoon all, I guess I am missing the benefit of using datasets with Crystal. For years I have written wrapper apps that used the Pull method and I let Crystal do all the sql work. Now I have an issue where the queries run for 4+ minutes so I don't want Crystal doing repeated legwork. I was under the impression that once the DataSet is filled and bound to the report the report (crystalviewer) would not need to re-run the...
0
1128
by: Joe | last post by:
Hi I have a Typed Dataset (TDS) and am using the derived class. I wrote a wrapper Class around the TDS class to manipulate the class {Add,Delete, return Dataset etc} - All is fine except when I add a record If I step thru the code the record is added to the TDS but when I return a reference to that TDS to the calling pgm the row is missing
8
1358
by: michael sorens | last post by:
I have written a few applications to read data from a database but now, as I turn my attention to writing to a database, I am apparently missing some fundamentals. I created a new database with a new (empty) table called Version. I then created a new data source in the Data Sources pane in Visual Studio 2005, yielding a DataSet named MyTestDataSet to reference the Version table. I then created a short WinForms program to just run ...
3
2832
by: Fred Chateau | last post by:
Still working on my XML DataSet... Having moved on past difficult and complex problems, resolved with the assistance of everyone here, I find myself facing yet another problem. My XML document breaks the schema. There are missing tags everywhere, on purpose I'm told, because we don't need them. I'm getting a "System.Data: There is no row at position <row number>" error. Hopefully I can workaround this issue. I need to find a way to...
0
9647
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
10162
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
9959
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
8988
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
7509
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
6744
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
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
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.