Overwritting XML file

purts

Member
Joined
Nov 12, 2008
Messages
8
Programming Experience
1-3
I have a XML file that is very basic and looks like this:

VB.NET:
<?xml version="1.0" encoding="utf-8"?>
<adminN>
  <texte>News 1</texte>
  <adminN>
    <texte>News 2</texte>
  </adminN>
</adminN>

I use the following code to make it appear in a label:

VB.NET:
Dim sr As StreamReader = New StreamReader(sXmlPath)
lNouvelles.Text = sr.ReadLine
sr.Close()

I'm using an editor (Cute Editor) to show the content of the XML file and then it's possible to add stuff. However, when I'm trying to add a new node to it, it does work and add it to the end of the file but the thing is I'd like it to overwrite the whole file with the new content in my editor. Any ideas?

Adding node code:

VB.NET:
    Protected Sub ajouterNouvelle(ByVal n As String)
        Dim doc As New XmlDocument()
        doc.Load(sXmlPath)
        MsgBox(lNouvelles.Text)
        Dim admin As XmlElement = doc.CreateElement("adminN")
        Dim nouvelle As XmlElement = doc.CreateElement("texte")
        nouvelle.InnerText = n
        MsgBox(n)
        MsgBox(nouvelle.InnerText)
        admin.AppendChild(nouvelle)
        doc.DocumentElement.AppendChild(admin)
        doc.Save(sXmlPath)
    End Sub
 
Back
Top