Hola a todos.
Resulta que estoy guardando unos valores en XML, pero tengo un problema a la hora de añadir otro registro al XML ya hecho.
El problema es el siguiente:
Creo el XML por primera vez. - Funciona bien
Pero si quiero agregar un dato a ese XML, no lo hace.
Lo que hace es borrarme el xml anterior y me lo llena con los nuevos datos. Pero yo no quiero eso si no que en vez de sobreescribirlos, me los añada como en otro nodo.
Utilizo el siguiente código:
Código:
Public Sub CrearXML(ByVal NombreXML As String, ByVal nombreAlbum As String, ByVal datos() As datosXML)
Dim doc As New System.Xml.XmlDocument()
Dim Albumes As System.Xml.XmlNode = doc.CreateElement("Albumes")
doc.AppendChild(Albumes)
Dim Album As System.Xml.XmlNode = doc.CreateElement("Album")
Dim atr As System.Xml.XmlAttribute = doc.CreateAttribute("Nombre")
Album.Attributes.Append(atr)
atr.InnerText = nombreAlbum
Dim i As Integer = 0
For x As Integer = 0 To datos.Count - 1
Dim Data As System.Xml.XmlNode = doc.CreateElement("Imagen")
Dim atributo As System.Xml.XmlAttribute = doc.CreateAttribute("Nombre")
Dim atributo2 As System.Xml.XmlAttribute = doc.CreateAttribute("Ruta")
atributo.InnerText = datos(x).Nombre
atributo2.InnerText = datos(x).path
Data.Attributes.Append(atributo)
Data.Attributes.Append(atributo2)
Album.AppendChild(Data)
Next
i += 1
Dim a As System.Xml.XmlNode = Album
Albumes.AppendChild(Album)
doc.Save("albumes.xml")
End Sub
¿Me podríais ayudar o decir, como lo debo de hacer para que funcione bien?
Por cierto está en vb.NET
Gracias!