Reading Xml with XmlReader in C#
Posted
by Gloria Huang
on Stack Overflow
See other posts from Stack Overflow
or by Gloria Huang
Published on 2010-03-14T09:06:19Z
Indexed on
2010/03/14
9:15 UTC
Read the original article
Hit count: 492
I'm trying to read the following Xml document as fast as I can and let additional classes manage the reading of each sub block.
<ApplicationPool><Accounts><Account><NameOfKin></NameOfKin><StatementsAvailable><Statement></Statement></StatementsAvailable></Account></Accounts></ApplicationPool>
I can't seem to format the above nicely :( However, I'm trying to use the XmlReader object to read each Account and subsequently the "StatementsAvailable". Do you suggest using XmlReader.Read and check each element and handle it?
I've thought of seperating my classes to handle each node properly. So theres an AccountBase class that accepts a XmlReader instance that reads the NameOfKin and several other properties about the account. Then I was wanting to interate through the Statements and let another class fill itself out about the Statement (and subsequently add it to an IList).
Thus far I have the "per class" part done by doing XmlReader.ReadElementString() but I can't workout how to tell the pointer to move to the StatementsAvailable element and let me iterate through them and let another class read each of those proeprties.
Sounds easy!
© Stack Overflow or respective owner