Hi I am parsing XML in silverlight, in my XML I have one tag is like
<test attribute1="123" />
<test1 attribute2="345">abc text</test1>
I am using XMLReader to parse xml like
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
// Parse the file and display each of the nodes.
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
//process start tag here
break;
case XmlNodeType.Text:
//process text here
break;
case XmlNodeType.XmlDeclaration:
case XmlNodeType.ProcessingInstruction:
break;
case XmlNodeType.Comment:
开发者_StackOverflow中文版 break;
case XmlNodeType.EndElement:
//process end tag here
break;
}
}
}
but the problem is that for test tag no EndElement is received? which is making my whole program logic wrong. (for test1 tag all works fine). Please help me out.
In the XmlNodeType.Element
case you could test whether it is an empty element using reader.IsEmptyElement
property which means that the element is opened and closed in the same iteration.
精彩评论