943,696 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 5692
  • VB.NET RSS
Jan 6th, 2009
0

Append Node to XML file Using Vb.net

Expand Post »
Dear All,

AM creating a XML file from my Database. I have created Sucessfully and now i need to append a another node to this below XML file

Ex : <TaskName Value="PS0002440" Status="Process" />

I use the following code to create this below XML file. Am passing the Value and status to this function to create the node and attribute..Can some one help me how to append new node without overwriting the existing one..

Public Sub xmlwrite(ByVal TaskId As String, ByVal Status As String)
Dim Tskid, Stats As String
Tskid = TaskId.ToString.Trim
Stats = Status.ToString.Trim
Dim myDoc As New Xml.XmlDocument
Dim rootTask As Xml.XmlNode = myDoc.AppendChild(myDoc.CreateElement("Task"))
Dim TaskStatusElements As Xml.XmlElement

TaskStatusElements = myDoc.CreateElement("TaskName")
With TaskStatusElements
.Attributes.Append(myDoc.CreateAttribute("Value"))
.Attributes("Value").Value = Tskid
.Attributes.Append(myDoc.CreateAttribute("Status"))
.Attributes("Status").Value = Stats
End With
rootTask.AppendChild(TaskStatusElements)
Dim myWriter As New Xml.XmlTextWriter("d:\test.xml", System.Text.Encoding.UTF8)

myWriter.Formatting = Xml.Formatting.Indented
myDoc.Save(myWriter)
myWriter.Close()

End Sub



<?xml version="1.0" encoding="utf-8"?>
<Task>
<TaskName Value="PS0002439" Status="Open" />
</Task>

Thanks and Regards,
Jayaprakash
Similar Threads
Reputation Points: 18
Solved Threads: 0
Light Poster
jaiprakash15 is offline Offline
27 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: vb.net error
Next Thread in VB.NET Forum Timeline: replace attribute value using vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC