XmlReader.IsEmptyElement Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
When overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <MyElement/>).
Assembly: System.Xml (in System.Xml.dll)
Property Value
Type: System.Booleantrue if the current node is an element (NodeType equals XmlNodeType.Element) that ends with />; otherwise, false.
StringBuilder output = new StringBuilder(); String xmlString = @"<book> <title>Pride And Prejudice</title> <price>19.95</price> <misc/> </book>"; // Create an XmlReader using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.IsEmptyElement) output.AppendLine(Environment.NewLine + "<" + reader.Name + "/>"); else output.Append("<" + reader.Name + ">"); break; case XmlNodeType.Text: output.Append(reader.Value); break; case XmlNodeType.Document: break; case XmlNodeType.EndElement: output.AppendLine("</" + reader.Name + ">"); break; } } } OutputTextBlock.Text = output.ToString();
Show: