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

Thread: Fast XML

Hybrid View

  1. #1
    Join Date
    May 2009
    Posts
    2

    Fast XML

    Assuming I have this simple XML:

    <book>
    <Author>person</Author>
    <Title>My Title</Title>
    </book>

    <book>
    <Author>person2</Author>
    <Title>My Title 2</Title>
    </book>
    etc...

    What is the fastest way to parse this file and buffer lists of authors and titles assuming there is a very large amount of entries in the file?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Fast XML

    Why would you want to parse the file yourself?

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Fast XML

    By parsing if you mean reading the XML file then try Dataset's ReadXML method.

  4. #4
    Join Date
    May 2009
    Posts
    2

    Re: Fast XML

    I am simply looking for the computationally-fastest method of buffering this information. This could be manually parsing or using any of the built in XML reading methods in C#, I just want to know which would be the best choice for huge datasets.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Fast XML

    Quote Originally Posted by tj1111 View Post
    I am simply looking for the computationally-fastest method of buffering this information. This could be manually parsing or using any of the built in XML reading methods in C#, I just want to know which would be the best choice for huge datasets.
    Well, you will have to measure before you can know anything. I would try it first with the built in parsing classes and see if that won't do what you need. There is no sense in rolling your own XML parser (Chok-full of bugs and inefficiencies) if the built in stuff works just fine. Using compiled xml node iterators can be faster than the DOM (XmlDocument) model, but again, try the easy way first,.

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

    Re: Fast XML

    XmlReader if the input file is huge. Otherwise XmlDocument would be just fine. The problem with XmlDocument is that it uses a chunk of memory because it essentially splits the input into a bunch of strings and keeps them all in memory. XmlReader is a forward-only reader and doesn't keep excess stuff in memory so if all you want to do is read the data once (and not query again) XmlReader is your friend.
    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
  •  





Click Here to Expand Forum to Full Width

Featured