Foros del Web » Programación para mayores de 30 ;) » .NET »

No está guardando los cambios

Estas en el tema de No está guardando los cambios en el foro de .NET en Foros del Web. Hola! Encontré un ejemplo de como agregar nodos a un XML usando C#... Pero no está guardando nada... en la consola se muestra el archivo ...
  #1 (permalink)  
Antiguo 04/10/2006, 11:58
 
Fecha de Ingreso: mayo-2006
Mensajes: 243
Antigüedad: 18 años
Puntos: 0
Pregunta No está guardando los cambios

Hola!

Encontré un ejemplo de como agregar nodos a un XML usando C#...
Pero no está guardando nada... en la consola se muestra el archivo como quedaría modificado, pero como que no está haciendo la instruccion:doc.Save(Console.Out);

Código:
using System;
using System.Xml;


namespace Microsoft.Framework.Samples
{
    class ModifyXmlDocumentSample
    {
        static void Main()
        {
            ModifyXmlDocumentSample xmlSample = new ModifyXmlDocumentSample();
            xmlSample.Run();
        }

        void InsertBook(XmlDocument doc)
        {

            XmlNode bookstore = doc.DocumentElement;

            XmlElement book = doc.CreateElement("book");
            book.SetAttribute("genre", "novel");
            book.SetAttribute("publicationdate", "1998");
            book.SetAttribute("ISBN", "0-553-21311-03");

            XmlElement title = doc.CreateElement("title");
            title.InnerText = "Moby Dick";
            book.AppendChild(title);

            XmlElement author = doc.CreateElement("author");
            XmlElement firstname = doc.CreateElement("first-name");
            firstname.InnerText = "Herman";
            XmlElement lastname = doc.CreateElement("last-name");
            lastname.InnerText = "Melville";
            author.AppendChild(firstname);
            author.AppendChild(lastname);
            book.AppendChild(author);

            XmlElement price = doc.CreateElement("price");
            price.InnerText = "12.99";
            book.AppendChild(price);

            bookstore.AppendChild(book);

        }

        public void Run()
        {
            //Load XML file
            XmlDocument doc = new XmlDocument();
            doc.Load("../../books.xml");
            Console.WriteLine("books.xml:");
            doc.Save(Console.Out);

            try
            {
                //add a new individual with book with title='Moby Dick'
                InsertBook(doc);
                Console.WriteLine("After Insert:");
                doc.Save(Console.Out);
            }
            finally
            {
                Console.Write("Press Enter to Exit");
                Console.ReadLine();
            }
        }
    }
}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:57.