Compartir vía


XmlNode.Value Propiedad

Definición

Obtiene o establece el valor del nodo.

public:
 virtual property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public virtual string Value { get; set; }
public virtual string? Value { get; set; }
member this.Value : string with get, set
Public Overridable Property Value As String

Valor de propiedad

El valor devuelto depende del NodeType del nodo:

Escriba Valor
Atributo Valor del atributo .
CDATASection Contenido de la sección CDATA.
Comentario Contenido del comentario.
Documento null.
DocumentFragment null.
DocumentType null.
Elemento null. Puede usar las InnerText propiedades o InnerXml para tener acceso al valor del nodo de elemento.
Entidad null.
EntityReference null.
Notación null.
ProcessingInstruction Todo el contenido excluyendo el destino.
Texto Contenido del nodo de texto.
SignificantWhitespace Caracteres de espacio en blanco. El espacio en blanco puede constar de uno o más caracteres de espacio, retornos de carro, fuentes de línea o pestañas.
Espacios en blanco Caracteres de espacio en blanco. El espacio en blanco puede constar de uno o más caracteres de espacio, retornos de carro, fuentes de línea o pestañas.
XmlDeclaration Contenido de la declaración (es decir, todo entre <?xml y ?>).

Excepciones

Establecer el valor de un nodo que sea de solo lectura.

Establecer el valor de un nodo que no se supone que tenga un valor (por ejemplo, un nodo Element).

Ejemplos

En el ejemplo siguiente se agrega un nuevo atributo al documento XML y se establece la Value propiedad del nuevo atributo.

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlNode root = doc.FirstChild;

    //Create a new attribute.
    string ns = root.GetNamespaceOfPrefix("bk");
    XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns);
    attr.Value = "novel";

    //Add the attribute to the document.
    root.Attributes.SetNamedItem(attr);

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        
        Dim doc As New XmlDocument()
        doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")
        
        Dim root As XmlNode = doc.FirstChild
        
        'Create a new attribute.
        Dim ns As String = root.GetNamespaceOfPrefix("bk")
        Dim attr As XmlNode = doc.CreateNode(XmlNodeType.Attribute, "genre", ns)
        attr.Value = "novel"
        
        'Add the attribute to the document.
        root.Attributes.SetNamedItem(attr)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

Se aplica a