Erik
Erik

Reputation: 95

C# - Saving Dataset to XML

Iam using the WriteXml() of a dataset to save the data I have in the dataset to an XML. When I save the dataset value into the XML file the format of the file is like code below.

I save the dataset like this: Order_Dataset.WriteXml(@"C:\Orders", XmlWriteMode.IgnoreSchema)

How can I write so that the XMLNS adress dose not shows in my XML file?? XmlWriteMode.IgnoreSchema should do the work but it wont

<Order_Dataset xmlns="http://tempuri.org/Order_Dataset.xsd"> <Order> <OrderName>Coffe</OrderName> <OrderID>1</OrderID> <OrderDate>2011-02-20T14:11:21+01:00</OrderDate> </Order>

Upvotes: 3

Views: 2574

Answers (2)

Peposh
Peposh

Reputation: 182

DataSet has internal variable fTopLevelTable that is changed only if a XML file is loaded. Use debugger to see difference after you load your hand changed XML into... This does the trick if you create DataSet by code or with ReadXmlSchema().

FieldInfo fieldInfo = typeof(DataSet).GetField("fTopLevelTable", BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(yourDS, true);

Upvotes: 0

Dominic Zukiewicz
Dominic Zukiewicz

Reputation: 8444

Have you tried changing the namespace of DataSet before saving it?

DataSet ds = new DataSet("MyDataSet");
ds.Namespace = "";
ds.WriteXml(...);

Upvotes: 4

Related Questions