public static RegistroPersonajes RecuperaXml(string f) { var toret = new RegistroPersonajes(); try { var doc = XDocument.Load(f); if (doc.Root != null && doc.Root.Name == EtqPersonajes) { var pers = doc.Root.Elements(EtqPersonaje); foreach (XElement personajexml in pers) { toret.addPersonaje(new Personaje( (string)personajexml.Attribute(EtqNombre), (string)personajexml.Attribute(EtqDescripcion))); } } } catch (XmlException) { toret.Clear(); } catch (IOException) { //toret.Clear(); } return(toret); }
public void GuardaXml(string nf) { RegistroPersonajes registro = RecuperaXml(); var doc = new XDocument(); var root = new XElement(EtqPersonajes); foreach (Personaje per in this.Personajes) { root.Add( new XElement(EtqPersonaje, new XAttribute(EtqNombre, per.Nombre), new XAttribute(EtqDescripcion, per.Descripcion))); } doc.Add(root); doc.Save(nf); }