Currently, it can append.....
but the type attributes "1" will write to the tag once i re-run the program...
Is that any way where it can check with the Xml file and continue the numbers instead of starting from 1....
Currently Xml file:
Hope to become:Code:<Books> <Book type="1"> <Author>ok</Author> <Section>1</Section> </Book> <Book type="2"> <Author>no</Author> <Section>2</Section> </Book> <Book type="1"> Not I wanted <Author>Peter</Author> <Section>7</Section> </Book> </Books>
My Coding:Code:<Books> <Book type="1"> <Author>ok</Author> <Section>1</Section> </Book> <Book type="2"> <Author>no</Author> <Section>2</Section> </Book> <Book type="3"> This is what I wanted <Author>Peter</Author> <Section>7</Section> </Book> </Books>
ThanksCode:Dim m As String = "1" Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim doc As New Xml.XmlDocument 'load file doc.Load("data.xml") 'create node 'get root node named users Dim Usersnode As Xml.XmlElement = doc.SelectSingleNode("//Books") 'add the new node Dim newNode As Xml.XmlElement = doc.CreateElement("Book") 'add attributes newNode.SetAttribute("type", m) 'add children nodes if any Dim child As Xml.XmlElement = doc.CreateElement("Author") child.InnerText = txtAuthor.Text newNode.AppendChild(child) child = doc.CreateElement("Section") child.InnerText = txtSection.Text newNode.AppendChild(child) 'add new node to users node Usersnode.AppendChild(newNode) m += 1 'save doc doc.Save("data.xml") End Sub




Reply With Quote