XmlElement.IsEmpty プロパティ

定義

要素のタグ形式を取得または設定します。

public:
 property bool IsEmpty { bool get(); void set(bool value); };
public bool IsEmpty { get; set; }
member this.IsEmpty : bool with get, set
Public Property IsEmpty As Boolean

プロパティ値

true要素を短いタグ形式 "<item/>" でシリアル化する場合は。長い形式の "falseitem</item><" を>します。

このプロパティを設定するときに、 trueに設定すると、要素の子が削除され、要素が短いタグ形式でシリアル化されます。 falseに設定すると、(要素にコンテンツがあるかどうかに関係なく) プロパティの値が変更されます。要素が空の場合は、長い形式でシリアル化されます。

このプロパティは、ドキュメント オブジェクト モデル (DOM) に対する Microsoft の拡張機能です。

次の例では、空の要素にコンテンツを追加します。

using System;
using System.Xml;

public class Sample {

  public static void Main() {

      XmlDocument doc = new XmlDocument();
      doc.LoadXml("<book>"+
                  "  <title>Pride And Prejudice</title>" +
                  "  <price/>" +
                  "</book>");

      XmlElement currNode = (XmlElement) doc.DocumentElement.LastChild;
      if (currNode.IsEmpty)
        currNode.InnerXml="19.95";

      Console.WriteLine("Display the modified XML...");
      Console.WriteLine(doc.OuterXml);
  }
}
 Imports System.Xml

public class Sample

  public shared sub Main()
  
      Dim doc as XmlDocument = new XmlDocument()
      doc.LoadXml("<book>" & _
                  "  <title>Pride And Prejudice</title>" & _
                  "  <price/>" & _
                  "</book>")   

      Dim currNode as XmlElement 
      currNode = CType (doc.DocumentElement.LastChild, XmlElement)
      if (currNode.IsEmpty)
        currNode.InnerXml="19.95"
      end if

      Console.WriteLine("Display the modified XML...")
      Console.WriteLine(doc.OuterXml)

  end sub
end class

注釈

このプロパティは、ドキュメント オブジェクト モデル (DOM) のMicrosoft拡張機能です。

適用対象