XmlElement.IsEmpty Propriedade
Definição
Obtém ou define o formato de marca do elemento.Gets or sets the tag format of the element.
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
Valor da propriedade
trueSe o elemento deve ser serializado no formato de marca curta " < item/ > "; false para o formato longo " < item > < /item > ".true if the element is to be serialized in the short tag format "<item/>"; false for the long format "<item></item>".
Ao definir essa propriedade, se for definida como true, os filhos do elemento serão removidos e o elemento será serializado no formato de marca abreviado.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. Se for definido como false, o valor da propriedade será alterado (independentemente de o elemento ter ou não conteúdo); se o elemento estiver vazio, ele será serializado no formato longo.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.
Essa propriedade é uma extensão da Microsoft do DOM (Modelo de Objeto do Documento).This property is a Microsoft extension to the Document Object Model (DOM).
Exemplos
O exemplo a seguir adiciona o conteúdo a um elemento vazio.The following example adds content to an empty element.
#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
Comentários
Essa propriedade é uma extensão da Microsoft do Modelo de Objeto do Documento (DOM).This property is a Microsoft extension of the Document Object Model (DOM).