我正在使用xmltextreader解析一些xml条目,并通过在不同的循环中对每个元素使用不同的textreader来查找所需的元素,如下所示:
Dim treader As XmlTextReader = New XmlTextReader(New StringReader(item.ToString))
While treader.Read
If treader.Name = "summary" Then
content = treader.ReadElementContentAsString
If String.IsNullOrEmpty(content) Then
content = "NOTHING"
Continue While
End If
contentList.Add(content)
Exit While
End If
End While我对我正在寻找的每个元素都做了同样的事情。现在,当我得到每一个的结果时,问题就出现了。我为每个元素使用一个数组列表,有时我会有一个不相等的数量,比如100表示摘要,100表示标题,99表示id等等……有没有一种更有效的方法来做到这一点:如果所有节点都在那里,那么检查条目,如果没有,就跳过它。
<entry>
<summary>
<id>
<published>
<uri>
<rule>
</entry>发布于 2010-12-05 11:48:50
我将创建一个entry对象,并将xml反序列化为一组entry对象。这将为linq和for each循环打开大门。查看XmlSerializer Class。我希望你的数据不会有99个I和100个其他字段。
https://stackoverflow.com/questions/4357104
复制相似问题