Created
December 3, 2015 21:37
-
-
Save Fhernd/6e8e633b67acdec8a2b9 to your computer and use it in GitHub Desktop.
Clase cliente que usa la clase AyudanteXml para insertar elementos y atributos en un documento XML.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Xml; | |
namespace Recetas.R0603 | |
{ | |
public class InsercionAgilNodos | |
{ | |
public static void Main() | |
{ | |
// Crea un nuevo documento XML: | |
XmlDocument docXml = new XmlDocument(); | |
XmlNode nodoDoc = docXml.CreateXmlDeclaration("1.0", "UTF-8", null); | |
// Inserción del nodo recién creado al documento: | |
docXml.AppendChild(nodoDoc); | |
// Creación e inserción de nuevo nodo para productos: | |
XmlNode nodoProductos = docXml.CreateElement("Productos"); | |
docXml.AppendChild(nodoProductos); | |
// Agrega dos productos: | |
XmlNode producto = AyudanteXml.AgregarElemento(nodoProductos, "Producto", null); | |
AyudanteXml.AgregarAtributo(producto, "ID", "10001"); | |
AyudanteXml.AgregarElemento(producto, "NombreProducto", "Café Negro"); | |
AyudanteXml.AgregarElemento(producto, "Precio", "8500"); | |
producto = AyudanteXml.AgregarElemento(nodoProductos, "Producto", null); | |
AyudanteXml.AgregarAtributo(producto, "ID", "10002"); | |
AyudanteXml.AgregarElemento(producto, "NombreProducto", "Cappuccino"); | |
AyudanteXml.AgregarElemento(producto, "Precio", "8500"); | |
// Muestra el contenido del archivo en la salida estándar: | |
docXml.Save(Console.Out); | |
Console.ReadLine (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment