Advertisement
Fhernd

InsercionAgilNodos.cs

Dec 3rd, 2015
16,658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3.  
  4. namespace Recetas.R0603
  5. {
  6.     public class InsercionAgilNodos
  7.     {
  8.         public static void Main()
  9.         {
  10.             // Crea un nuevo documento XML:
  11.             XmlDocument docXml = new XmlDocument();
  12.             XmlNode nodoDoc = docXml.CreateXmlDeclaration("1.0", "UTF-8", null);
  13.            
  14.             // Inserción del nodo recién creado al documento:
  15.             docXml.AppendChild(nodoDoc);
  16.            
  17.             // Creación e inserción de nuevo nodo para productos:
  18.             XmlNode nodoProductos = docXml.CreateElement("Productos");
  19.             docXml.AppendChild(nodoProductos);
  20.            
  21.             // Agrega dos productos:
  22.             XmlNode producto = AyudanteXml.AgregarElemento(nodoProductos, "Producto", null);
  23.             AyudanteXml.AgregarAtributo(producto, "ID", "10001");
  24.             AyudanteXml.AgregarElemento(producto, "NombreProducto", "Café Negro");
  25.             AyudanteXml.AgregarElemento(producto, "Precio", "8500");
  26.            
  27.             producto = AyudanteXml.AgregarElemento(nodoProductos, "Producto", null);
  28.             AyudanteXml.AgregarAtributo(producto, "ID", "10002");
  29.             AyudanteXml.AgregarElemento(producto, "NombreProducto", "Cappuccino");
  30.             AyudanteXml.AgregarElemento(producto, "Precio", "8500");
  31.            
  32.             // Muestra el contenido del archivo en la salida estándar:
  33.             docXml.Save(Console.Out);
  34.             Console.ReadLine ();
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement