Created
December 3, 2015 21:30
-
-
Save Fhernd/1f6afc94e3e612f19af5 to your computer and use it in GitHub Desktop.
Clase ayudante para la creación de 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 AyudanteXml | |
{ | |
// Agregar un nuevo nodo un documento XML: | |
public static XmlNode AgregarElemento(XmlNode nodoPadre, | |
string nombreEtiqueta, string contenido) | |
{ | |
// Crear el nuevo nodo: | |
XmlNode nuevoNodo = nodoPadre.OwnerDocument.CreateElement(nombreEtiqueta); | |
// Agrega el nuevo nodo en el nodo padre: | |
nodoPadre.AppendChild(nuevoNodo); | |
// Valida si el nodo contendrá un nodo de texto: | |
if (contenido != null) | |
{ | |
XmlNode nodoContenido ; | |
nodoContenido = nodoPadre.OwnerDocument.CreateTextNode(contenido); | |
nuevoNodo.AppendChild(nodoContenido); | |
} | |
return nuevoNodo; | |
} | |
// Agregar un nuevo atributo a un documento XML: | |
public static XmlNode AgregarAtributo(XmlNode nodoPadre, | |
string nombreAtributo, string contenido) | |
{ | |
XmlAttribute nuevoAtributo; | |
nuevoAtributo = nodoPadre.OwnerDocument.CreateAttribute(nombreAtributo); | |
nuevoAtributo.Value = contenido; | |
nodoPadre.Attributes.Append(nuevoAtributo); | |
return nuevoAtributo; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment