Export (0) Print
Expand All

XmlElement.IsEmpty Property

Gets or sets the tag format of the element.

[Visual Basic]
Public Property IsEmpty As Boolean
[C#]
public bool IsEmpty {get; set;}
[C++]
public: __property bool get_IsEmpty();
public: __property void set_IsEmpty(bool);
[JScript]
public function get IsEmpty() : Boolean;
public function set IsEmpty(Boolean);

Property Value

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

When setting this property, if set to true, the children of the element are removed and the element is serialized in the short tag format. If set to false, the value of the property is changed (regardless of whether or not the element has content); if the element is empty, it is serialized in the long format.

This property is a Microsoft extension to the Document Object Model (DOM).

Remarks

This property is a Microsoft extension of the Document Object Model (DOM).

Example

[Visual Basic, C#, C++] The following example adds content to an empty element.

[Visual Basic] 
Imports System
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

[C#] 
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);

  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;

int main()
{
       XmlDocument* doc = new XmlDocument();
       doc->LoadXml(S"<book>  <title>Pride And Prejudice</title>  <price/></book>");     
  
       XmlElement* currNode = dynamic_cast<XmlElement*> (doc->DocumentElement->LastChild);
       if (currNode->IsEmpty)
         currNode->InnerXml=S"19.95"; 
 
       Console::WriteLine(S"Display the modified XML...");
       Console::WriteLine(doc->OuterXml);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlElement Class | XmlElement Members | System.Xml Namespace

Show:
© 2014 Microsoft