Solved

Need Help Reading an XML Document

Posted on 2006-07-13
2
264 Views
Last Modified: 2010-05-18
I have this XML document and I need to read it, but I'm having trouble getting the nested information such as:

I want to read the <location> information into an array list for each Byte compare type ex ("office", "Quark")

<ByteCompareList>
    <ByteCompareType>
      <name>Office</name>
      <ByteCompareLocations>
        <Location>
          <at>43</at>
          <value>135</value>
        </Location>
        <Location>
          <at>44</at>
          <value>134</value>
        </Location>
        <returnFiletype>Access</returnFiletype>
      </ByteCompareLocations>
      <ByteCompareLocations>
        <Location>
          <at>32</at>
          <value>243</value>
        </Location>
        <Location>
          <at>33</at>
          <value>255</value>
        </Location>
        <returnFiletype>Word</returnFiletype>
      </ByteCompareLocations>
    </ByteCompareType>
    <ByteCompareType>
      <name>Quark</name>
      <ByteCompareLocations>
        <Location>
          <at>66</at>
          <value>143</value>
        </Location>
        <Location>
          <at>68</at>
          <value>98</value>
        </Location>
        <returnFiletype>Quark Template</returnFiletype>
      </ByteCompareLocations>
    </ByteCompareType>
  </ByteCompareList>

any help is greatly appreciated.

Thanks
0
Comment
Question by:asmyatt
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17101328
This:

    XmlDocument doc = new XmlDocument();
    doc.Load("Your document.xml");

    XmlNodeList nodes = doc.SelectNodes("ByteCompareList/ByteCompareType/ByteCompareLocations/Location");

Will get you all of the Location nodes in the document. How you go about putting them into an ArrayList will depend on how you need to work with them.
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17101768
why do you wanna read that data again in a different logical format?
xmldocument manages the data with an internal tree.
so you would get into memory problems if you have large xml files.
you can work with the xmlnodelist, which references every location nodes you need.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question