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

속성 값

Boolean

true if the element is to be serialized in the short tag format "<item/>"; false for the long format "<item></item>".

이 속성을 설정할 때 true로 설정하면 요소의 자식이 제거되고 요소는 짧은 태그 형식으로 serialize됩니다. false로 설정하면 요소에 내용이 있는지 여부와 상관없이 속성 값이 변경되고, 요소가 비었으면 긴 형식으로 serialize됩니다.

이 속성은 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

예제

다음 예제에서는 빈 요소에 콘텐츠를 추가합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book>  <title>Pride And Prejudice</title>  <price/></book>" );
   XmlElement^ currNode = dynamic_cast<XmlElement^>(doc->DocumentElement->LastChild);
   if ( currNode->IsEmpty )
      currNode->InnerXml = "19.95";

   Console::WriteLine( "Display the modified XML..." );
   Console::WriteLine( doc->OuterXml );
}
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 확장입니다.

적용 대상