다음을 통해 공유


XmlNode.Value 속성

정의

노드의 값을 가져오거나 설정합니다.

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

속성 값

반환되는 값은 노드의 NodeType 값에 따라 달라집니다.

유형
특성 특성의 값입니다.
CDATASection CDATA 섹션의 내용입니다.
주석 주석의 내용입니다.
문서 null;
DocumentFragment null;
DocumentType null;
요소 null; 또는 InnerXml 속성을 사용하여 InnerText 요소 노드의 값에 액세스할 수 있습니다.
개체 null;
EntityReference null;
표기법 null;
ProcessingInstruction 대상을 제외한 전체 콘텐츠입니다.
텍스트 텍스트 노드의 내용입니다.
SignificantWhitespace 공백 문자입니다. 공백은 하나 이상의 공백 문자, 캐리지 리턴, 줄 바꿈 또는 탭으로 구성될 수 있습니다.
공백 공백 문자입니다. 공백은 하나 이상의 공백 문자, 캐리지 리턴, 줄 바꿈 또는 탭으로 구성될 수 있습니다.
XmlDeclaration 선언의 내용(즉, ?xml과 ?>사이의 <모든 항목)입니다.

예외

읽기 전용인 노드의 값을 설정합니다.

값이 없도록 되어 있지 않은 노드의 값(예: 요소 노드)을 설정합니다.

예제

다음 예제에서는 XML 문서에 새 특성을 추가하고 새 특성의 속성을 설정합니다 Value .

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

적용 대상