Create XML file - According to the Value, add elements under corresponding range

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
i'm using VB.NET.

i'm using this codes to create this XML.
<Employee>
<EmpItem CV="120" PL1="2" PL2="3" /EmpItem>
<EmpItem Cv="2" PL1="6" PL2="4" /EmpItem>
<EmpIten Cv="234" PL1="4" PL"4" /EmpItem>
<DataName>
</Employee>

VB.NET:
TextBox1.Text = "C:\Program\Emp.mdb"
If File.Exists(TextBox1.Text) Then
            Dim strSQL As String = "Select ItemID,pl11,pl12 from MG10 where ItemID <> 0"
            Dim myConnection As New OleDbConnection(strConn)
            myConnection.Open()
            Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
            Dim myReader As OleDbDataReader = myCommand.ExecuteReader
            
            Dim myXWriter As XmlTextWriter
            Dim myWriter As StreamWriter
            Dim myStream As MemoryStream
            myStream = New MemoryStream

            myXWriter = New XmlTextWriter(myStream, Encoding.UTF8)
            myXWriter.Formatting = Formatting.Indented
            myXWriter.Indentation = 2

            myXWriter.WriteStartDocument()
            myXWriter.WriteStartElement("Employee")

           While myReader.Read
                myXWriter.WriteStartElement("Item")
                myXWriter.WriteAttributeString("CV", myReader(0))
                myXWriter.WriteAttributeString("PL1", myReader(1))
               myXWriter.WriteAttributeString("PL2", myReader(2))
                myXWriter.WriteEndElement()
            End While

            myXWriter.WriteFullEndElement()
            myXWriter.WriteFullEndElement()
            myXWriter.WriteEndDocument()
            myXWriter.Flush()

           myStream.Seek(0, SeekOrigin.Begin)

            Dim strConfig2 As String = New StreamReader(myStream).ReadToEnd()
            myWriter = File.CreateText("C:\Example.xml")
            myWriter.WriteLine(strConfig2)
            myWriter.Close()
        End If

anyway is there to create an XML like this...
<Employee>
<EmpRange min="0" max="99">
<EmpItem Cv="2" PL1="6" PL2="4">
</EmpRange>
<EmpRange min="100" max="199">
<EmpItem CV="120" PL1="2" PL2="3">
</EmpRange>
<EmpRange min="200" max="299">
<EmpIten Cv="234" PL1="4" PL"4">
<EmpRange>
<DataName>
</Employee>

according to the CV values can i add the EmpItems in corresponding Range. and the CV values will be random numbers. so if CV value is 34 then it should be under <EmpRange min="0" max="99">. likewise can we create an XML file to add EmpItems according to the range the CV value.

if you have any idea how to create this please help me... if you can provide any help then it will be a great help for me....

thanks in advanace.
 
The great thing about xml is it's extremly flexable.

Look up XMLNODE

all you need to do is itterate through the document for the correct node, then add the new node to it.

There's a lot of examples

do a google search

XML NODE vb.net
 
Back
Top