XmlNode.Value Propriedade

Definição

Obtém ou define o valor do nó.Gets or sets the value of the node.

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 da propriedade

String

O valor retornado depende do NodeType do nó:The value returned depends on the NodeType of the node:

TypeType ValorValue
AtributoAttribute O valor do atributo.The value of the attribute.
CDATASectionCDATASection O conteúdo da seção CDATA.The content of the CDATA Section.
ComentárioComment O conteúdo do comentário.The content of the comment.
DocumentoDocument null.null.
DocumentFragmentDocumentFragment null.null.
DocumentTypeDocumentType null.null.
ElementoElement null.null. Você pode usar as propriedades InnerText ou InnerXml para acessar o valor do nó do elemento.You can use the InnerText or InnerXml properties to access the value of the element node.
EntidadeEntity null.null.
EntityReferenceEntityReference null.null.
NotationNotation null.null.
ProcessingInstructionProcessingInstruction Todo o conteúdo, exceto o destino.The entire content excluding the target.
TextoText O conteúdo do nó de texto.The content of the text node.
SignificantWhitespaceSignificantWhitespace Os caracteres de espaço em branco.The white space characters. O espaço em branco pode consistir em um ou mais caracteres de espaço, retornos de carro, alimentação de linha ou tabulações.White space can consist of one or more space characters, carriage returns, line feeds, or tabs.
Espaço em brancoWhitespace Os caracteres de espaço em branco.The white space characters. O espaço em branco pode consistir em um ou mais caracteres de espaço, retornos de carro, alimentação de linha ou tabulações.White space can consist of one or more space characters, carriage returns, line feeds, or tabs.
XmlDeclarationXmlDeclaration O conteúdo da declaração (ou seja, tudo entre < ? XML e? > ).The content of the declaration (that is, everything between <?xml and ?>).

Exceções

Definindo o valor de um nó que é somente leitura.Setting the value of a node that is read-only.

Definindo o valor de um nó que não deveria ter um valor (por exemplo, um nó de elemento).Setting the value of a node that is not supposed to have a value (for example, an Element node).

Exemplos

O exemplo a seguir adiciona um novo atributo ao documento XML e define a Value Propriedade do novo atributo.The following example adds a new attribute to the XML document and sets the Value property of the new attribute.

#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

Aplica-se a