dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Preparing a Dictionary out of a huge XML.

  1. #1
    Join Date
    Apr 2004
    Posts
    123

    Preparing a Dictionary out of a huge XML.

    I have the below mentioned XML and i need to populate a dictionary out of it...

    Code:
    <IntrestedBookSet>
    <IntrestedBook AuthorName="XXX" Book="YYY" ID="1"/>
    <IntrestedBook AuthorName="XXX" Book="AAA" ID="2"/>
    <IntrestedBook AuthorName="XXX" Book="BBB" ID=" "/>
    <IntrestedBook AuthorName="CCC" Book="YYY" ID="5" Link="tttt"/>
    <IntrestedBook AuthorName="CCC" Book="YZY" ID="7"/>
    <IntrestedBook AuthorName="XXX" Book="XDY" ID="10"/>
    <IntrestedBook AuthorName="CCC" Book="BBB" ID="3" Link="ssss"/>
    </IntrestedBookSet>
    I need a dictionary which should be of the following form

    Dictionary<string,List<string>>...where key should represent author name and value should represent books written by him..

    In normal cases it's very easy...but my issue is that the XML is very very huge...more than 1 million Intrestedbook nodes are there...and when i use XMLDocument to parse this xml...the CPU utilization shoots up...so.i'm planning for XMLReader...which i read somewhere is very fast compared to XMLDocument..

    now,the question is...how do i parse it efficiently...as you might notice there is a one to many mapping between AuthorName and Book...should i be checking for the elements or for attributes...what would be an efficient parsing algorithm...???

    Thanks in advance..

    Mmx
    Last edited by mmx_nexus; April 16th, 2008 at 08:54 AM.

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Preparing a Dictionary out of a huge XML.

    Just read using an XmlReader and it'll be fine. XmlDocument loads the entire thing into memory at the same time, XmlReader doesn't. That's why it'll be better to use it.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)