You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Shawn Englot <se...@gmail.com> on 2014/06/20 19:39:56 UTC
XercesDOMParser and setValidationScheme(Val_Auto) problems
I am having a problem with the XercesDOMParser, and the behaviour that I am
seeing when using the XercesDOMParser::Val_Always Validation Scheme.
I have an xml document and a simple xsd. The xsd provides a constraint
using 'unique': Here is the xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="authors">
<xs:complexType>
<xs:sequence>
<xs:element name="author" maxOccurs="unbounded" type="xs:string"/>
<xs:element name="lastmodified" type="xs:date" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueAuthor">
<xs:selector xpath="author"/>
<xs:field xpath="."/>
</xs:unique>
</xs:element>
</xs:schema>
Here is the xml that has a constraint error since the element author must
be unique.
<?xml version="1.0" encoding="UTF-8"?>
<authors
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="author.xsd">
<author>tom</author>
<author>tim</author>
<author>tim</author>
<lastmodified>2011-11-11</lastmodified>
</authors>
When I validate this xml against the xsd using XercesDOMParser::Val_Always
it catches the error as expected, however when I use
XercesDOMParser::Val_Auto, the document parses successfully without error.
If I add another error, such as an unexpected element Val_Auto will catch
this error, so I know for sure that the xsd is being read.
I have configured the parser as follows:
domParser.setValidationConstraintFatal(true);
domParser.setDoNamespaces(true);
domParser.setDoSchema(true);
domParser.setValidationSchemaFullChecking(true);
domParser.setIdentityConstraintChecking(true);
domParser.setExternalNoNamespaceSchemaLocation(schemaFilePath);
domParser.setValidationScheme(XercesDOMParser::Val_Auto);
domParser.parse(xmlFilePath);
Note that DOMPrint also behaves similar way: ie, unless I set the
validation scheme to Always it does not catch the unique constraints:
$ DOMPrint -n -s -f author.xml
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><authors xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="author.xsd">
<author>tom</author>
<author>tim</author>
<author>tim</author>
<lastmodified>2011-11-11</lastmodified>
</authors>
$ DOMPrint -v=always -n -s -f author.xml
Error at file "/home/xml/author.xml", line 7, column 23
Message: element 'authors' declares duplicate identity constraint unique
values
Is this behaviour expected or have I missed something?
What I was expecting is that if the xml document specifies an xsd and it
can be found, and I have enabled all possible validation in the parser that
Val_Auto should also catch the unique constraints.