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.
DocumentFragmentnull.
DocumentTypenull.
요소null. InnerText 또는 InnerXml 속성을 사용하여 Element 노드의 값에 액세스할 수 있습니다.
엔터티null.
EntityReferencenull.
Notationnull.
ProcessingInstruction 대상을 제외한 전체 콘텐츠입니다.
텍스트 텍스트 노드의 내용입니다.
SignificantWhitespace 공백 문자입니다. 공백은 하나 이상의 스페이스 문자, 캐리지 리턴, 줄 바꿈 또는 탭 등으로 구성될 수 있습니다.
공백 공백 문자입니다. 공백은 하나 이상의 스페이스 문자, 캐리지 리턴, 줄 바꿈 또는 탭 등으로 구성될 수 있습니다.
XmlDeclaration 선언의 내용(즉, ?xml과 ?>) 사이의 <모든 내용입니다.

예외

읽기 전용인 노드의 값을 설정하는 경우

값이 없어야 하는 노드의 값을 설정하는 경우(예: Element 노드)

예제

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

#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

적용 대상