How to create XML programtically

Posted by Oswaldlily under VB.NET on 4/2/2014 | Points: 10 | Views : 1552 | Status : [Member] | Replies : 4
How to create XML programtically for following code

<?xml version="1.0" standalone="yes"?>
<DocumentElement>

<Table>
<Sno>aaaa</Sno>
<Code>bbbbb</Code>
</Table>

<Table>
<Sno>4545</Sno>
<Code>bbccc</Code>
</Table>

</DocumentElement>




Responses

Posted by: Brahmam on: 4/2/2014 [Member] Starter | Points: 25

Up
0
Down
Please check this url

http://www.aspdotnet-suresh.com/2010/12/how-to-insert-data-into-xml-and-how-to.html

brahmam

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 4/2/2014 [Member] Starter | Points: 25

Up
0
Down
Hi..
Refer the below link..........
http://www.dotnetcode.in/2012/03/reading-and-writing-xml-data-in-aspnet.html


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 4/2/2014 [Member] Starter | Points: 25

Up
0
Down
Dim tb As New DataTable("Table")
tb.Columns.Add("Name", Type.[GetType]("System.String"))
tb.Columns.Add("Currency", Type.[GetType]("System.String"))
Dim st As [String] = ""
If dg.Name = "DataGridView1" Then
st = "D:\text.xml"
ElseIf dg.Name = "DataGridView2" Then
st = "D:\text1.xml"
End If

For Each row As DataGridViewRow In dg.Rows

Dim r As DataRow = tb.NewRow()
r("Name") = row.Cells(0).Value 'row1 cell 1
r("Currency") = row.Cells(1).Value 'row1 cell2
tb.Rows.Add(r)

Next
tb.WriteXml(st)


Problem:

if dg.Rows.count=0, for each wont execute & when comes to tb.writexml(st),
I expect xml file to look like

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<Table>
<Sno> </Sno>
<Code> </Code>
</Table>

</DocumentElement>

but coming wrongly as

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
</Table>

</DocumentElement>

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 4/2/2014 [Member] Starter | Points: 25

Up
0
Down
easy way to generate xml from c#. please look at this url :

http://ajaypatelfromsanthal.blogspot.in/2012/08/serializedeserialize-xml-from-class_5789.html

Ajay
ajaypatelfromsanthal.blogspot.in

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response