XmlElement.IsEmpty Właściwość

Definicja

Pobiera lub ustawia format tagu elementu.

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

Wartość właściwości

Boolean

truejeśli element ma być serializowany w formacie krótkiego tagu "item/>"; false dla długiego formatu "<item></item>".<

Podczas ustawiania tej właściwości, jeśli ustawiono wartość true, elementy podrzędne elementu zostaną usunięte, a element zostanie serializowany w formacie krótkiego tagu. Jeśli jest ustawiona falsewartość , wartość właściwości zostanie zmieniona (niezależnie od tego, czy element ma zawartość); jeśli element jest pusty, jest serializowany w długim formacie.

Ta właściwość jest rozszerzeniem firmy Microsoft do modelu obiektów dokumentów (DOM).

Przykłady

Poniższy przykład dodaje zawartość do pustego elementu.

#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

Uwagi

Ta właściwość jest rozszerzeniem firmy Microsoft modelu obiektów dokumentów (DOM).

Dotyczy