xsdrapidxml

How to parse an XSD file with RapidXML


Does RapidXML have the capability to validate/parse a XML file with its associated schema, i.e. XSD file? I was under the assumption that an XML parser would have the capability to do both congruently. If not, why is it deemed unnecessary to validate/parse the associated schema? I checked RapidXML's documentation and found no mention of schema or xsd.

I am currently parsing XML files likeso:

  rapidxml::file<> xmlFile("BeerLog.xml");
  rapidxml::xml_document<> doc;
  doc.parse<0>(xmlFile.data());

The following sudo-code might give you a better idea of what I am looking for:

  rapidxml::file<> xmlFile("BeerLog.xml", "BeerLog.xsd");  

or even:

  rapidxml::file<> xmlFile("BeerLog.xml");    
  rapidxml::file<> xsdFile("BeerLog.xsd");
  rapidxml::xml_document<> doc;
  doc.parse_with_schema<0>(xsdFile.data(), xmlFile.data());

Solution

  • Your impression is wrong, accessing the content of a XML and validation against a scheme are quite distinct topics- even if the former is useful for the latter. Especially light-wight and fast parsers don't support validation, and a quick glance into the documentation shows this:

    W3C Compliance. RapidXml is not a W3C compliant parser, primarily because it ignores DOCTYPE declarations

    Given also, that there are quite different scheme languages (XSD, RNG, DTD, ...) even support of one would not mean its the one you would like to.

    You will also have to take into account, that there are many XML files, which are just well-formed and do not conform to any scheme - somebody may want to process them nevertheless.