I have a project in which I manage an XML file with C # UWP.
The problem is that when I delete or modify a node in the XML document, the space of that node is not deleted and it is under the root, causing me to get an error.
I give an example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Usuario>
<Nombre>
<Valor>Antonio</Valor>
</Nombre>
<Contrasena>
<Valor>Antonio1989</Valor>
</Contrasena>
<Apellido>
<Valor>Pérez</Valor>
</Apellido>
</Usuario>
This is how it would look like without any changes, but when I delete the "Password" node, for example, it looks something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Usuario>
<Nombre>
<Valor>Antonio</Valor>
</Nombre>
<Apellido>
<Valor>Pérez</Valor>
</Apellido>
</Usuario>o>
<Valor>Pérez</Valor>
</Apellido>
</Usuario>
The code fragment I use in C # is the following (the "path" is a IsolatedStorageFileStream
):
public void EliminarNodo(string nodo)
{
XmlDocument Documento = new XmlDocument();
Documento.Load(path);
XmlElement Root = Documento.DocumentElement;
XmlNode NodoEliminar = Root.GetElementsByTagName(nodo)[0];
Root.RemoveChild(NodoEliminar);
Documento.Save(AlmacenDatos.Stream(Ruta));
}