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 de la propiedad NodeType del nodo.

Tipo Value
Atributo El valor del atributo.
CDATASection Contenido de la sección CDATA.
Comentario El contenido del comentario.
Documentonull.
DocumentFragmentnull.
DocumentTypenull.
Elementonull. Puede usar las propiedades InnerText o InnerXml para obtener acceso al valor del nodo element.
Entidadnull.
EntityReferencenull.
Notaciónnull.
ProcessingInstruction Todo el contenido, salvo el destino.
Texto El contenido del nodo de texto.
SignificantWhitespace Caracteres de espacio en blanco. El espacio en blanco puede estar formado por uno o varios caracteres de espacio, retornos de carro, saltos de línea o tabulaciones.
Espacio en blanco Caracteres de espacio en blanco. El espacio en blanco puede estar formado por uno o varios caracteres de espacio, retornos de carro, saltos de línea o tabulaciones.
XmlDeclaration Contenido de la declaración (es decir, todo entre <?xml y ?>).

Excepciones

Establecer el valor de un nodo que es de sólo lectura.

Establecer el valor de un nodo que no debe tener 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.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew 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 );
}
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