View Single Post
  #1 (permalink)  
Old December 17th, 2007, 06:22 PM
Sojan80 Sojan80 is offline
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Parsing XML File

I'm using a C# Console Application. I have an XML and matching XSD File. Here's a small sample of my XML:
    <FileDate>5/23/2007 3:03:05 PM</FileDate>
        <HSCOURSE id="1">
            <HSCOURSE_TERM_OTHER />
            <HSCOURSE_TITLE>British Literature</HSCOURSE_TITLE>
        <HSCOURSE id="2">
            <HSCOURSE_TERM>Acad Year</HSCOURSE_TERM>
            <HSCOURSE_TERM_OTHER />

What I need to do is:
- pass in an array of node names e.g. string[] nodeList = { "FIRST_NAME", "LAST_NAME", "SSN", "BIRTH_DATE", "HSCOURSE" };
- loop through each application node in the XML file obtaining all instances for that application of the nodes (and their children if any) passed in the array including attributes for each of the nodes passed in
- write those values to screen then go to the next application in the file and so on.

I can load the xml into an XmlDocument and am able to create a nodelist containing all of the application nodes.

I cannot however get the sequence to allow me to loop through through the application nodes retrieving all the instances of the nodes passed in. For example there could be no <HS_COURSE> listings in which case it shows up as <HS_COURSE/> or there could be ten of them and I need to be able to grab them all.

How do I go about looping through each application obtaining all instances of the given nodes in the array as well as any child nodes that node may contain?

Reply With Quote