[xsd-users] Parser maintains state between parsing attempts?

Gerard Lanois gerardlanois at gmail.com
Mon Jul 10 19:37:24 EDT 2006


Version 1 of my program, works as expected (a Bannana arrives, and is
successfully parsed):

char* msg = ... // read text from somewhere
std::istringstream iss(msg);

try {
  std::auto_ptr<Bannana::type> b(Bannana(iss,
xml_schema::flags::dont_validate));
}
catch (...) {
}


------------------------------------------------------------------


Version 2 of my program - doesn't work (explanation below).

char* msg = ... // read text from somewhere
std::istringstream iss(msg);

try {
  std::auto_ptr<Apple::type> a(Apple(iss, xml_schema::flags::dont_validate));
}
catch (...) {
}

try {
  std::auto_ptr<Bannana::type> b(Bannana(iss,
xml_schema::flags::dont_validate));
}
catch (...) {
}


----------------------------------------------------------

In this version of the program, the attempted parsing of an incoming
Bannana causes the Apple to throw an execption, as you would
expect.

However, when the program makes the attempt to parse the
Bannana as a Bannana, the parser fails.


The error is occurring down inside

        template <typename C>
        auto_ptr<xercesc::DOMDocument>
        parse (xercesc::DOMInputSource const& is,
               xercesc::DOMErrorHandler& eh,
               properties<C> const& prop,
               bool validate);

which is a function in namespace xsd::cxx::xml::dom.

This parse function (toward the bottom) has these lines of code:

          bits::error_handler_proxy<C> ehp (eh);
          parser->setErrorHandler (&ehp);

          auto_ptr<DOMDocument> doc (parser->parse (is));

          if (ehp.failed ())
            doc.reset ();

The call to parser->parse() is setting ehp.failed_ to true.


I think this means that the failed attempt to parse a Bannana
by the Apple constructor is leaving the DOMBuilder::parser()
in a state where it cannot successfully parse anything further.

Is there some initialization or re-initialization I should perform
between the Apple and Bannana parsing attempts?

What I'm trying to do:  I have an input stream which can have two
types of documents arriving (Apple, and Bannana).  I don't have
any way of knowing in advance what is going to arrive.  Is there
an easier way to find out what the document type is before
submitting it?  (brute force peeking into the document?)

Thanks in advance for your help.

-Gerard



More information about the xsd-users mailing list