Hi all
I seems that there are two ways of validating an xml document with XML
Schema.
1. Create a XMLParser object and pass it an XMLSchema object as an
argument. If you use this parser object with etree.parse() or
etree.fromstring(), it validates the document against the schema while
parsing.
2. Parse the document first, and then validate it using
XMLSchema.validate() or XMLSchema.assertValid().
I have always used the first method – I was unaware of the second one.
However, I have just found a particular error that is detected by the second
method, but not by the first one.
The error is the use of duplicate “id” attributes, if it is specified in
the schema as being of type “xs:ID”. I have a document with duplicate ids.
Validating with the first method passes. Validating the same document, with the
same schema, using the second method, gives the following -
Is this a bug? Should I always use the second method?
I am using lxml version 4.1.1.
Thanks
Frank Millman
P.S. This is a copy of a message I posted on 26/03/2017. I got no reply to
that, so I thought I would try again. I was using version 3.6.4 then, but the
behaviour is the same with 4.1.1.