I am attempting to port some Java code utilizing Xerces v3.2.2 that loads a schema file, retrieves the XSModel* and parses it into some custom data structures.
JAVA
import org.apache.xerces.XSLoader;
import org.apache.xerces.XSModel;
XSImplementation xsLoader = null;
XSLoader xsLoader = null;
XSModel xsModel = null;
xsImpl = (XSImplmentation) domRegistry.getDOMImplementation("XS-Loader");
xsLoader = xsImpl.createXSLoader(null);
xsModel = xsLoader.loadURI("path-to-schema.xsd");
myDataStruct = new MyDataStruct(xsModel);
I have been unable to find anything in Xerces-c documentation that would yield similar results. As far as I can tell, I can access the XSModel*
from the xercesc::GrammarResolver*
through the xercesc::AbstractDOMParser
but this would require me to derive from the parser as it is a protected function.
CPP
#include <xercesc/parsers/XercesDOMParser.hpp>
using namespace xercesc;
class MyDOMParser : public XercesDOMParser
{
public:
using AbstractDOMParser::getGrammarResolver;
};
int main()
{
XMLPlatformUtils::Initialize();
MyDOMParser parser;
parser.loadGrammar("path-to-schema.xsd", Grammar::GrammarType::SchemaGrammarType);
auto resolver = parser.getGrammarResolver();
auto xsModel = resolver->getXSModel();
MyDataStruct myDataStruct{xsModel};
return 0;
}
Is this the route I must go? Will this even work? Are there examples out in the wild that show a better way of doing this?
The above solution I attempted for CPP does appear to achieve what I'm trying to accomplish. By deriving from XercesDOMParser
I am able to access the GrammarResolver
and therefore the XSModel
. The model seems to contain the data my data structure requires for parsing.