How to use libxml2 validate a xml with a schema in

2019-07-04 16:52发布

问题:

I use libxml2 to validate xmls with a schema, and because of some reasons I must use schema version 1.1, so I began my schema header like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">

and I wrote a compleType like this:

<xs:complexType name="test-type">
    <xs:all>
        <xs:element name="test"></xs:element>
        <xs:element name="test1" minOccurs="0" maxOccurs="4"></xs:element>
    </xs:all>
</xs:complexType>

It's valid in version1.1, but invalid in version1.0. When I used my program to parse this schema:

xmlSchemaParseCtxtPtr ctxt;
xmlLineNumberDefault(1);
ctxt=xmlSchemaNewParserCtxt("schema.xsd");
_xmlSchema* _schema = xmlSchemaParse(ctxt);

I got a null-pointer in _schema. But if i removed that upper complexType, everything was OK. So I thought may be the root cause was libxml2 only supported schema version1.0 "in my code". So is there any solution to make libxml2 work with schema version1.1? I must use some of its new features. Any suggestion will help! Thanks!

回答1:

libxml2 has not been updated to support XSD 1.1. As far as I am aware there is no active development on the product so this is unlikely to happen. You will need to find a different schema processor.