[xsd-users] Storing sequence data in C++/Parser

Boris Kolpackov boris at codesynthesis.com
Fri Mar 20 12:16:45 EDT 2009


Hi Vinaya,

In the future please use a more descriptive subject line. For this and
other posting guidelines, see:

http://www.codesynthesis.com/support/posting-guidelines.xhtml


Vinaya Shrestha <vinayashrestha at gmail.com> writes:

> class Member_pimpl: public Member_pskel
> {
>         private:
>                string id;
>                string name;
>                string dob;
> };
>
> ...
>
> I have used these two classes to store the XML information. Things were
> fine, when there was a single member node. But as I added up more member
> nodes, I could not figure out how to store all the Member nodes.

The Member_pimpl parser will be called for each member element in your
XML document and it is up to you to make sure that the subsequent calls
don't override the data stored on the current iterator. You can, for
example, use std::vector to sore an entry for each member element:

class Member_pimpl: public Member_pskel
{
private:
  struct Member
  {
    string id;
    string name;
    string dob;
  };

  std::vector<Member> members_;
};

You can do

members_.push_back (Member ());

in pre() and then in id(), name(), and dob() fill in the members using
members_.back (), for example:

members_.back ().id = id;

Boris




More information about the xsd-users mailing list