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 によって異なります。

Type
属性 属性の値。
CDATASection CDATA セクションの内容。
コメント コメントの内容。
ドキュメントnull.
DocumentFragmentnull.
DocumentTypenull.
要素null. InnerText プロパティまたは InnerXml プロパティを使用すると、要素ノードの値にアクセスできます。
エンティティnull.
EntityReferencenull.
表記null.
ProcessingInstruction ターゲットを含まない全体の内容。
Text テキスト ノードの内容。
SignificantWhitespace 空白文字。 空白は、1 つ以上の空白文字、キャリッジ リターン、ライン フィード、またはタブによって構成できます。
空白 空白文字。 空白は、1 つ以上の空白文字、キャリッジ リターン、ライン フィード、またはタブによって構成できます。
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

適用対象