I have the following code to stream from a large XML file. However, some <Campaign/>
elements are skipped. Any reason for this?
public static IEnumerable<XElement> StreamItem(string uri)
{
using (var reader = XmlReader.Create(uri))
{
XElement campaign = null;
reader.MoveToContent();
// Loop through <Campaign /> elements
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Campaign")
{
campaign = XNode.ReadFrom(reader) as XElement;
yield return campaign;
}
}
}
}
Update:
The XML file is well-formed and has the following structure.
<CRoot>
<Campaign CampaignID="136">
<!-- other nested elements -->
</Campaign>
<Campaign CampaignID="137">
<!-- other nested elements -->
</Campaign>
<!-- etc -->
</CRoot>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…