我有这样的xml文件
<Person>
<Name>ABC</Name>
<Title>Prof</Title>
<Class>1</Class>
</Person>
<Person>
<Name>XYZ</Name>
<Title />
<Class>2</Class>
</Person>
我的 C# 代码是这样的
XMLReader reader = XmlReader.Create(new StringReader(xmlBlock));
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
//Do Something
break;
case XmlNodeType.Text:
//Do Something
break;
case XmlNodeType.EndElement:
//Do Something
break;
}
}
如何在我的代码中识别标题标签中存在多少标签?
<title>Prof</title> or <title />