Hi,

How do i write to xml format for the below data. This is sample parsing data that i need to save in xml format. Please guide me !

<field id="0" value="0210"/>
  <field id="2" value="00"/>
  <field id="3" value="320000"/>
  <field id="4" value="000000068519"/>
  <field id="5" value="000000000000"/>
  <field id="7" value="5465464545"/>
  <field id="11" value="000021"/>
  <field id="12" value="05488565"/>
  <field id="13" value="1014"/>
  <field id="15" value="1015"/>
  <field id="32" value="040"/>
  <field id="34" value=""/>
  <field id="37" value="000000000234"/>
  <field id="38" value=""/>
  <field id="39" value="00"/>
  <field id="48" value="0200900000001620283889454    040001 ANDREW                                      1000000000110A       

000000068519           000000000000           000000000000"/>
  <field id="49" value="360"/>
  <field id="52" value=""/>
  <field id="54" value=""/>
  <field id="102" value=""/>
  <field id="103" value=""/>

i have done as below but it seems not what i expect for.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim writer As New XmlTextWriter(Application.StartupPath & "1.xml", System.Text.Encoding.UTF8)
        writer.WriteStartDocument(True)
        writer.Formatting = Formatting.Indented
        writer.Indentation = 2
        writer.WriteStartElement("")

        writer.WriteEndElement()
        writer.WriteEndDocument()
        writer.Close()
        'createNode()
    End Sub

the result should be like this when i open the xml

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ISOBIT>
<field id="0" value="0210"/>
  <field id="2" value="00"/>
  <field id="3" value="320000"/>
  <field id="4" value="000000068519"/>
  <field id="5" value="000000000000"/>
  <field id="7" value="1014091237"/>
  <field id="11" value="000021"/>
  <field id="12" value="091237"/>
  <field id="13" value="1014"/>
  <field id="15" value="1015"/>
  <field id="32" value="040"/>
  <field id="34" value=""/>
  <field id="37" value="000000000234"/>
  <field id="38" value=""/>
  <field id="39" value="00"/>
  <field id="48" value="0200900000001620283889454    040001 ANDREW                                      1000000000110A       000000068519           000000000000           000000000000"/>
  <field id="49" value="360"/>
  <field id="52" value=""/>
  <field id="54" value=""/>
  <field id="102" value=""/>
  <field id="103" value=""/>
</ISOBIT>

The questions are:
where do you get the data from?
Are you trying to add something to the xml, or editing exsiting nodes, or writing the whole xml?

Please provide some more details.

hi,
thank you for the reply, i'm getting this data from other server and send to my server. this message will be capture by web services from server and send to personal computer. Once receive this data i have to save to XML format. I just need to know how to save into XML format the data i receive.
Thank you.

Ok, since you don't provide the format in what you receive the data, I will give you a dummy example.

IMPORTANT: You have to add a reference to System.Xml.Linq

Sub Main()

		Dim myXmlFile As String = "dummy.xml"
		Dim xDoc As New XDocument
		Dim topLevel As XElement = <ISOBIT/>
		Dim dummyData As Dictionary(Of Integer, String) = CreateDummyData()

		For Each dummy In dummyData
			topLevel.Add(<field id=<%= dummy.Key %> value=<%= dummy.value %>/>)
		Next

		xDoc.Add(topLevel)
		xDoc.Save(myXmlFile)
	End Sub

	Private Function CreateDummyData() As Dictionary(Of Integer, String)

		Dim dummy As New Dictionary(Of Integer, String)
		For i As Integer = 65 To 90
			dummy.Add(i, New String(Chr(i), 10))
		Next
		Return dummy

	End Function

Content of the xml file:

<?xml version="1.0" encoding="utf-8"?>
<ISOBIT>
  <field id="65" value="AAAAAAAAAA" />
  <field id="66" value="BBBBBBBBBB" />
  <field id="67" value="CCCCCCCCCC" />
  <field id="68" value="DDDDDDDDDD" />
  <field id="69" value="EEEEEEEEEE" />
  <field id="70" value="FFFFFFFFFF" />
  <field id="71" value="GGGGGGGGGG" />
  <field id="72" value="HHHHHHHHHH" />
  <field id="73" value="IIIIIIIIII" />
  <field id="74" value="JJJJJJJJJJ" />
  <field id="75" value="KKKKKKKKKK" />
  <field id="76" value="LLLLLLLLLL" />
  <field id="77" value="MMMMMMMMMM" />
  <field id="78" value="NNNNNNNNNN" />
  <field id="79" value="OOOOOOOOOO" />
  <field id="80" value="PPPPPPPPPP" />
  <field id="81" value="QQQQQQQQQQ" />
  <field id="82" value="RRRRRRRRRR" />
  <field id="83" value="SSSSSSSSSS" />
  <field id="84" value="TTTTTTTTTT" />
  <field id="85" value="UUUUUUUUUU" />
  <field id="86" value="VVVVVVVVVV" />
  <field id="87" value="WWWWWWWWWW" />
  <field id="88" value="XXXXXXXXXX" />
  <field id="89" value="YYYYYYYYYY" />
  <field id="90" value="ZZZZZZZZZZ" />
</ISOBIT>

Hi,
Thank so much for the information. it helps a lot....
thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.