How to configure Xerces-C ++ to handle XIncludes before checking XML schema

Consider the XML file, config.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration
  xsi:noNamespaceSchemaLocation = "rules.xsd"
  xmlns:xsi                     = "http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xi                      = "http://www.w3.org/2001/XInclude"
>
  <xi:include href="bunnies.xml" />
  <xi:include href="doggies.xml" />
</Configuration>

where rules.xsd is an XML schema that describes the structure and limitations of config.xml after processing XIncludes.


Using xmllint , you can execute XIncludes before checking the XML schema from the command line:

xmllint --xinclude --schema rules.xsd config.xml

Invalid changes for the child element bunnies.xml or doggies.xml will be selected by the xmllint tool.


Xerces-C XIncludes XML-, , XML . , , Xerces DOMLSParser.

XML Schema - XIncludes - , , XML- XIncludes; .


XInclude.cpp Xerces-C :

static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser       *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration  *config = parser->getDomConfig();

config->setParameter(XMLUni::fgDOMNamespaces, true);
config->setParameter(XMLUni::fgXercesSchema, true);
config->setParameter(XMLUni::fgXercesHandleMultipleImports, true);
config->setParameter(XMLUni::fgXercesSchemaFullChecking, true);
config->setParameter(XMLUni::fgXercesDoXInclude, true);

config->setParameter(XMLUni::fgDOMValidate, false);

fgDOMValidate - , XIncludes.
fgDOMValidate - ; XIncludes do!


- Xerces-C, ? , , , , XIncludes - - , XML- XML / ?

, - Xerces-C API, !

+4

Source: https://habr.com/ru/post/1658232/


All Articles