Sign In/My Account | View Cart  
advertisement

Article:
 Learning C# XML
Subject: Descrepancies between Java and C#
Date: 2002-03-21 10:52:01
From: Niel Bornstein
Response to: Descrepancies between Java and C#

Dennis -


You raise a very interesting point. I did a little research and discovered the XmlReader.IsEmptyElement property.


The Microsoft documentation (http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlTextReaderClassIsEmptyElementTopic.asp) reports that IsEmptyElement is "true if the current node is an element (NodeType equals XmlNodeType.Element) that ends with />; otherwise, false." And further, "A corresponding EndElement node is not generated for empty elements."


I have not tested this myself, but it seems that one could check for this case by inserting the following code at the very end of the XmlNodeType.Element case between the call to StartElement() and the break statement:


if (reader.IsEmptyElement) {
EndElement(reader.NamespaceURI, reader.Name, reader.Name);
}


The intent is to immediately fire off a call to EndElement() when the element is empty, since the framework does not do it automatically.


Niel


No Previous Message Previous Message Move up to Parent Message Up Next Message No Next Message


Sponsored By: