GNOME Bugzilla – Bug 720192
The QName value of the xsi:type attribute does not resolve to a type definition
Last modified: 2021-07-05 13:26:44 UTC
Using libxml 2.9.1 Today got example xml and two xsd files from an external system. The example file validates in Java, but does not in xmllint. The problem is in libxml2 or the Java parser? The example XML file I got: <?xml version="1.0"?> <ArrayOfTestType xmlns="http://example.com/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <TestType xmlns="" i:type="Test"> <Id>test1</Id> </TestType> <TestType xmlns="" i:type="Test"> <Id>test2</Id> </TestType> </ArrayOfTestType> The "root" XSD file: <?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="a1.xsd"/> <xs:element name="ArrayOfTestType"> <xs:complexType> <xs:sequence> <xs:element ref="TestType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> The a1.xsd referenced by the previous one: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Id" type="xs:string"/> <xs:element name="TestType" type="T_TestType"/> <xs:complexType name="Test"> <xs:complexContent> <xs:extension base="T_TestType"> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="T_TestType"> <xs:sequence> <xs:element ref="Id"/> </xs:sequence> </xs:complexType> </xs:schema> Test Java code which reports valid xml: import javax.xml.XMLConstants; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.*; import org.xml.sax.SAXException; import java.io.*; public class ProtocolValidator { public static void main(String [] args) throws Exception { Source schemaFile = new StreamSource(new File("a.xsd")); Source xmlFile = new StreamSource(new File("test.xml")); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(schemaFile); Validator validator = schema.newValidator(); try{ validator.validate(xmlFile); System.out.println(xmlFile.getSystemId() + " is valid"); } catch (SAXException e) { System.out.println(xmlFile.getSystemId() + " is NOT valid"); System.out.println("Reason: " + e.getLocalizedMessage()); } } } Test xmllint command line code: $ xmllint --schema a.xsd test.xml <?xml version="1.0"?> <ArrayOfTestType xmlns="http://example.com/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <TestType xmlns="" i:type="Test"> <Id>test1</Id> </TestType> <TestType xmlns="" i:type="Test"> <Id>test2</Id> </TestType> </ArrayOfTestType> test.xml:3: element TestType: Schemas validity error : Element 'TestType', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value '{}Test' of the xsi:type attribute does not resolve to a type definition. test.xml:6: element TestType: Schemas validity error : Element 'TestType', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value '{}Test' of the xsi:type attribute does not resolve to a type definition. test.xml fails to validate
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxml2/-/issues/ Thank you for your understanding and your help.