| | |
Append Node to XML file Using Vb.net
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
![]() |
•
•
Join Date: Nov 2008
Posts: 27
Reputation:
Solved Threads: 0
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
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
Other Threads in the VB.NET Forum
- Previous Thread: vb.net error
- Next Thread: replace attribute value using vb.net
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account add application array basic beginner browser button buttons center check click code combo cpu crystalreport cuesent database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel exists fade file-dialog filter forms ftp generatetags html images input insert intel listview mobile module monitor mysql net number open output panel passingparameters picturebox picturebox2 port print printing printpreview problem regex reuse right-to-left searchvb.net select settings shutdown socket sqldatbase sqlserver storedprocedure survey tcp temperature textbox timespan transparency trim txttoxmlconverter user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





