[xsd-users] Extracting DOMDocument from anyType

Iain Sharp isharp at atis.org
Tue Jan 23 04:06:12 EST 2018


All,

I am using XSD Tree to build a C++ object model and parse XML for a set of pre-defined XSD files.

The normal parsing process is:

  1.  Take the incoming XML
  2.  Using XercesDOMParser parse the XML to a DOMDocument
  3.  Peek at the tag of the root element to determine its type (similar to the second approach in "How do I handle XML data of an unknown type?" in the FAQ)
  4.  Parse the DOMDocument to  the C++ data structure of the appropriate type using the appropriate parser method generated by XSD

I now want to expand the parsing to extract an appropriate type instance for an anyType element which will contain one of the types already handled by the parser. To do this, the obvious thing is to get the DOMDocument for the anyType and pass this through steps 3 and 4 of the existing parsing process above. However, the dom_content_document() for the anyType element doesn't seem to be returning a populated document.

I have processed the XSD using "-generate-any-type". If I call dom_content() on the anyType element then I see all the tags and values belonging to the contained type as I would expect. However, dom_content_document() doesn't seem to contain any data:
xercesc::DOMDocument& dcd = anyTypeElement.dom_content_document();
dcd.getNodeName() is "#document"
dcd.hasChildNodes() is false
dcd.getDocumentElement() is NULL

Am I missing something about how to get a DOMDocument for an anyType element?


Thanks

Iain



More information about the xsd-users mailing list