Share via


IsEmptyElement

 

This method allows the client to determine the difference between elements that have a closing tag, but do not contain content, and elements that do not have a closing tag.

Syntax

  
BOOL IsEmptyElement ();  

Return Value

Returns TRUE if the current element ends with />; otherwise, returns FALSE.

Remarks

IsEmptyElement returns FALSE for the following element:

<element attribute="123"></element>  

IsEmptyElement returns TRUE for the following element:

<element attribute="123"/>  

Note that when writing elements, an XmlNodeType_EndElement node is not generated for empty element start tags.

If the method is not applicable, it will return FALSE.

You should save the value of IsEmptyElement before processing attributes, or call MoveToElement to make IsEmptyElement valid after processing attributes.

IsEmptyElement returns FALSE when XmlReader is positioned on an attribute node, even if attribute's parent element is empty.

The following code tests whether the reader is currently on an empty element:

if (FAILED(hr = pReader->GetPrefix(&pwszPrefix, &cwchPrefix))) {  
   wprintf(L"Error getting prefix, error is %08.8lx", hr);  
   return -1;  
}  
if (FAILED(hr = pReader->GetLocalName(&pwszLocalName, NULL))) {  
   wprintf(L"Error getting local name, error is %08.8lx", hr);  
   return -1;  
}  
if (cwchPrefix > 0)  
   wprintf(L"Element: %s:%s\n", pwszPrefix, pwszLocalName);  
else  
   wprintf(L"Element: %s\n", pwszLocalName);  
  
if (FAILED(hr = WriteAttributes(pReader))) {  
   wprintf(L"Error writing attributes, error is %08.8lx", hr);  
   return -1;  
}  
if (FAILED(hr = pReader->MoveToElement())) {  
   wprintf(L"Error moving to the element that owns the current attribute node, error is %08.8lx", hr);  
   return -1;  
}  
// fEmptyElement is a saved value of pReader->IsEmptyElement()   
// as it was before WriteAttributes(pReader))  
if(fEmptyElement)   
   wprintf(L" (empty)");   

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlReader Methods