xml parsing using xmltextreader
I am parsing some xml entries using the xmltextreader and looking for the elements I need by using different textreaders for each in a different loop as follows:
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
and I do the same for each element I am looking for. Now the problem arises when I get the results for each. I use an arraylist for each element and at times I will h开发者_运维百科ave an unequal amount like 100 for summary, 100 for title , 99 for id etc... is there a more efficient way of doing this by checking the entry if all the nodes are there and then just skipping it if it's not.
<entry>
<summary>
<id>
<published>
<uri>
<rule>
</entry>
I would make an entry object and deserialize the xml as a list of entry objects. That would open the door to linq and for each loops. Check out the XmlSerializer Class. I hope your data doesn't have 99 ids and 100 of some other field.
精彩评论