473,395 Members | 2,437 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,395 software developers and data experts.

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.Namespace = "RatesXML"
Dim xmlFilename As String = "myXmlDocument.xml"
Dim fsWriteXml As New System.IO.FileStream(xmlFilename,
System.IO.FileMode.Create)
Dim xmlWriter As New
System.Xml.XmlTextWriter(fsWriteXml,System.Text.En coding.Unicode)
dataset.WriteXml(xmlWriter)
fsWriteXml.Close()
dataset.Dispose()
Dim newDataSet As New DataSet("New DataSet")
Dim fsReadXml As New System.IO.FileStream(xmlFilename,
System.IO.FileMode.Open)
Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
newDataSet.ReadXml(myXmlReader)
myXmlReader.Close()

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 4579
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.Namespace = "RatesXML"
Dim xmlFilename As String = "myXmlDocument.xml"
Dim fsWriteXml As New System.IO.FileStream(xmlFilename,
System.IO.FileMode.Create)
Dim xmlWriter As New
System.Xml.XmlTextWriter(fsWriteXml,System.Text.En coding.Unicode)


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
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.FileStream stream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);

// Create an XmlTextWriter with the fileStream.
System.Xml.XmlTextWriter xmlWriter =
new System.Xml.XmlTextWriter(stream,
System.Text.Encoding.Unicode);

// Write Declarative with 'Standalone' attribute set to 'yes'.
xmlWriter.WriteStartDocument(true);

// Write to the file with the WriteXml method.
thisDataSet.WriteXml(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
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...
3
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...
2
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...
0
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...
2
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...
3
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...
0
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...
8
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...
3
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.