Click here to Skip to main content
13,400,969 members (39,250 online)
Click here to Skip to main content
Add your own
alternative version


69 bookmarked
Posted 16 May 2000

A simple STL based XML parser

, 16 May 2000
Rate this:
Please Sign up or sign in to vote.
This is a small non-validating XML parser based purely on STL
  • Download source files - 10 Kb
  • This is a small XML parser, based purely on STL. There are two main classes XmlStream and XmlParser. XmlParser.h contains most of the parsing code. It has several state variable, which can be split up into two categories:

    1. Buffer state - Shows where we are parsing from
    2. Parsing state - Shows what we have found
    XmlParser makes extensive use of offsets to keep track of its state. This is done by design. In order to maximize speed it does not do any string copies.

    To start parsing declare an instance of the class XmlStream and setup the buffer that you want to parse. An example is included in Parser.cpp. Call parse in XmlStream, passing in a pointer to the buffer and the buffers length. You will see screen output showing what has been found. This is simple debug output and can be turned off.

    XmlNotify is used as an interface class to notify a subscriber of nodes and elements being found. There is a pointer to a subscriber in the XmlStream class. The subscriber can be set using setSubscriber.

    Notice that no XML document declaration is included nor is a schema included. If those exist in your buffer don't send them to the parser. Later, the ability to remove these, will added in the code to step through these. so this is a non-validating parser. There is one bug in the parser. When an empty node is encountered it will be reported as an element this will be fixed later. An example of this is included in the sample code.

    If you have any suggestions or improvements let me know.


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    David Hubbard
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    GeneralRe: multiple entries of the same name Pin
    mikeguz14-Oct-05 18:47
    membermikeguz14-Oct-05 18:47 
    GeneralNodes have the same name BUG Pin
    Ken Lee9-Apr-03 21:43
    memberKen Lee9-Apr-03 21:43 
    GeneralRe: Nodes have the same name BUG Pin
    Ken Lee9-Apr-03 21:52
    memberKen Lee9-Apr-03 21:52 
    Generalpretty print of stream Pin
    fazer777-Feb-03 19:00
    memberfazer777-Feb-03 19:00 
    Generalattributes Pin
    fazer777-Feb-03 18:56
    memberfazer777-Feb-03 18:56 
    GeneralBug fix for null nodes Pin
    BenJeremy2-Jan-03 11:06
    memberBenJeremy2-Jan-03 11:06 
    GeneralRe: Bug fix for null nodes Pin
    BenJeremy6-Jan-03 6:04
    memberBenJeremy6-Jan-03 6:04 
    GeneralAnoying bug for an xml parser Pin
    yarp21-Nov-02 21:42
    memberyarp21-Nov-02 21:42 
    GeneralRe: Anoying bug for an xml parser Pin
    yarp21-Nov-02 22:17
    memberyarp21-Nov-02 22:17 
    GeneralSearch Pin
    David Frame7-Feb-02 6:18
    memberDavid Frame7-Feb-02 6:18 
    GeneralRe: Search Pin
    ifgarcia20-Apr-05 22:55
    memberifgarcia20-Apr-05 22:55 
    Generalanother bug in XmlParser.h Pin
    Pika28-Jul-01 0:47
    memberPika28-Jul-01 0:47 
    Questionnotify on end-of-node? Pin
    Chris Losinger28-Mar-01 18:44
    memberChris Losinger28-Mar-01 18:44 
    AnswerRe: notify on end-of-node? Pin
    gok17-Feb-03 18:11
    membergok17-Feb-03 18:11 
    GeneralRe: notify on end-of-node? Pin
    khmerkidnow29-Jul-04 14:50
    memberkhmerkidnow29-Jul-04 14:50 
    GeneralBug in XmlParser.h Pin
    John Osborn11-Oct-00 11:07
    sussJohn Osborn11-Oct-00 11:07 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.180218.2 | Last Updated 17 May 2000
    Article Copyright 2000 by David Hubbard
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid