XmlElement.IsEmpty Proprietà

Definizione

Ottiene o imposta il formato di tag dell'elemento.

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

Valore della proprietà

Boolean

truese l'elemento deve essere serializzato nel formato di tag breve "item/>"; false per il formato lungo "<<item></item>".

Se si imposta questa proprietà su true, i figli dell'elemento vengono rimossi e l'elemento viene serializzato nel formato di tag breve. Se la si imposta su false, il valore della proprietà viene modificato (indipendentemente dal fatto che l'elemento abbia un contento o meno). Se l'elemento è vuoto, viene serializzato nel formato lungo.

Questa proprietà è un'estensione Microsoft di Document Object Model (DOM).

Esempio

Nell'esempio seguente viene aggiunto contenuto a un elemento vuoto.

#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

Commenti

Questa proprietà è un'estensione Microsoft del modello a oggetti document (DOM).

Si applica a