[xsd-users] Assertion fails when parsing xerces DOMDocument with
keep_dom flag
Boris Kolpackov
boris at codesynthesis.com
Mon Oct 13 10:03:52 EDT 2008
Hi Brian,
Brian Kohan <Brian.Kohan at jhuapl.edu> writes:
> I am trying to upgrade from Xerces2.7 to 3.0 and from XSD 2.3.1 to 3.2.
> The following code worked in 2.3.1 but is now generating an assertion
> failure:
>
> XMLPlatformUtils::Initialize();
> XercesDOMParser* parser = new XercesDOMParser();
> parser->parse(docUri);
> DOMDocument* doc = parser->adoptDocument();
>
> MyType* myObj = new MyType(*doc->getDocumentElement(),
> xml_schema::flags::keep_dom |
> xml_schema::flags::dont_initialize |
> xml_schema::flags::dont_validate
> );
In XSD 3.1.0 we have implemented exception-safe DOMDocument
ownership transfer which requires that the xml_schema::dom::auto_ptr
object owning the DOMDocument be associated with the DOMDocument
itself so that the generated code can reset it when it assumes
the ownership. All this is normally done under the hood by one
of the parsing functions but since you are using the parsing
constructors directly, you will need to do it yourself:
xml_schema::dom::auto_ptr<DOMDocument> doc = parser->adoptDocument();
doc->setUserData (xml_schema::dom::tree_node_key, doc.get (), 0);
MyType* myObj = new MyType(*doc->getDocumentElement(),
xml_schema::flags::keep_dom |
xml_schema::flags::dont_initialize |
xml_schema::flags::dont_validate);
After the successful construction, myObj will own the DOM document
and doc will be reset. If the construction fails then doc still
owns the document.
Boris
More information about the xsd-users
mailing list