XmlNode.Value Eigenschap

Definitie

Hiermee wordt de waarde van het knooppunt opgehaald of ingesteld.

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

Waarde van eigenschap

De geretourneerde waarde is afhankelijk van het NodeType knooppunt:

Typ Waarde
Kenmerk De waarde van het kenmerk.
CDATASection De inhoud van de CDATA-sectie.
Commentaar De inhoud van de opmerking.
Document null.
DocumentFragment null.
DocumentType null.
Element null. U kunt de InnerText of InnerXml eigenschappen gebruiken om toegang te krijgen tot de waarde van het elementknooppunt.
Entiteit null.
EntityReference null.
Notatie null.
ProcessingInstruction De volledige inhoud met uitzondering van het doel.
Tekst De inhoud van het tekstknooppunt.
SignificantWhitespace De spatietekens. Witruimte kan bestaan uit een of meer spatietekens, regelterugloop, regelfeeds of tabs.
Whitespace De spatietekens. Witruimte kan bestaan uit een of meer spatietekens, regelterugloop, regelfeeds of tabs.
XmlDeclaration De inhoud van de declaratie (dat wil zeggen alles tussen <?xml en ?>).

Uitzonderingen

De waarde van een knooppunt instellen dat alleen-lezen is.

Het instellen van de waarde van een knooppunt dat geen waarde moet hebben (bijvoorbeeld een elementknooppunt).

Voorbeelden

In het volgende voorbeeld wordt een nieuw kenmerk toegevoegd aan het XML-document en wordt de Value eigenschap van het nieuwe kenmerk ingesteld.

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

Van toepassing op