CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    3

    Parsing a complex XML file using XMLTextReader

    I have a very large number of a very large-sized set of XML documents. I need to parse them and extract the content of the elements but since these are large files, I intend to use SAX rather than DOM. However, when I use XMLTextReader, it is difficult to parse elements that have text + some more elements and then some more text. How can I do this? I'm using C#.
    I have put up an example of the type of XML file I am referring to.
    <?xml version="1.0"?>
    <catalog>
    <book id="bk101">This is the first book by
    <author>Gambardella, Matthew</author> which has the name
    <title>XML Developer's Guide</title> on
    <genre>Computer</genre>and is available at a price of
    <price>$44.95</price>. It was published on
    <publish_date>2000-10-01</publish_date>
    in<place>London</place>
    </book>
    ....
    ...
    ...
    ...
    </catalog>

    I need to extract the inner elements separately and also the text "This is the first book by Gambardella, Matthew which has the name XML Developer's Guide on Computer and is available at a price of $44.95. It was published on 2000-10-01 in London.

    Could someone please guide me on how to do this? A code snippet would be more than welcome. Thanks in advance to anyone who replies.

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Parsing a complex XML file using XMLTextReader

    If you use the NodeType property you can decide which type of node you're dealing with and based on that do the various checks you need to do.
    There's a type for elements, values, space etc making your task relative easy.

    If not, then post some of the code you have already and we'll see if we can guide you onwards.

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