Export DataTable to XML file (URGENT !)

A

atef shehata

hi all,

i have a dataset with many datatables , i want to know how to export
only one datatable to xml file ( not the whole dataset tables) ?

any suggestions , comments will be very helpful .

thanks for your help.

atef
 
D

Deepak

I can think of a way around.
Create a new dataset and add the table from the original dataset.
Then write this new dataset to xml.

Regards,

Deepak
[I code, therefore I am]
 
A

atef shehata

thanks Deepak for you help .

l'm already using the same solution you mentioned.

but in my situation ....

i have a dataset per each webform , each dataset holds many datatables
representing the queries data .

this queries cached (on the server) as xml files .(around 380 tables , some exceeds 2 million of records !!)

so we can say , every datatable on the dataset can be cached according
to some generic parameters(lifetime and its expire date ,no. of
records ,...)

after saving the xml file , in the same webform or another one the
cached data will be used (loaded into an intermediate dataset then
copied into the actual datatable in the actual dataset )

so i want to avoid this extra step of copying the data from the
intermediate dataset to the actual dataset.

any comments .

thanks Deepak

atef
 
G

Guest

Atef
I thought about the issue here, and wrote a simple method which will write your datatable to xml. I will say that there is a lot of room for optimization in my method. But the idea is to get the ball rolling. I do wish that MS will have a WriteToXML method for the DataTables in the next version of the framework. Anyway here is what I wrote

public static void WriteToXML(DataTable dt, string fileName

//write the datatable to xm
string xml = "<?xml version=\"1.0\" standalone=\"yes\"?>"
xml += "<newDataSet></newDataSet>"
XmlDocument doc = new XmlDocument()
doc.LoadXml(xml)
XmlTextWriter xw = new XmlTextWriter(fileName,System.Text.Encoding.UTF8)
XmlElement rootElement = doc.DocumentElement

foreach(DataRow row in dt.Rows

XmlElement rowElement = doc.CreateElement("Table")
for(int i= 0; i < dt.Columns.Count; i++

XmlElement[] colElement = new XmlElement[dt.Columns.Count]
colElement = doc.CreateElement(dt.Columns.Caption)
colElement.InnerText = row.ToString()
rowElement.AppendChild(colElement)

rootElement.AppendChild(rowElement)


doc.WriteTo(xw)
xw.Close()



Regards

Deepa
[I Code, therefore I am



----- atef shehata wrote: ----

thanks Deepak for you help

l'm already using the same solution you mentioned

but in my situation ...

i have a dataset per each webform , each dataset holds many datatable
representing the queries data

this queries cached (on the server) as xml files(around 380 tables , some exceeds 2 million of records !!

so we can say , every datatable on the dataset can be cached accordin
to some generic parameters(lifetime and its expire date ,no. o
records ,...

after saving the xml file , in the same webform or another one th
cached data will be used (loaded into an intermediate dataset the
copied into the actual datatable in the actual dataset

so i want to avoid this extra step of copying the data from th
intermediate dataset to the actual dataset

any comments

thanks Deepak

ate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top