I’m an XML neophyte having some weird issues with parsing a schema. Here’s a minimal example you can run:
#! /usr/bin/env python
from lxml import etree
from StringIO import StringIO
XML = StringIO('''<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xs:complexType name="ArrayOfDocumentLink">
<xs:complexContent>
<xs:restriction base="soapenc:Array">
<xs:attribute ref="soapenc:arrayType" wsdl:arrayType="tns:DocumentLink[]"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>''')
etree.XMLSchema(file=XML)
gives
lxml.etree.XMLSchemaParseError: complex type 'ArrayOfDocumentLink', attribute 'base': The QName value '{http://schemas.xmlsoap.org/soap/encoding/}Array' does not resolve to a(n) simple type definition., line 7
I’m clueless. Various mailing lists and this SO question suggest that there’s a workaround that involves collecting all the definitions into an external file. But that doesn’t really help a neophyte understand what’s going on. Any insight is much appreciated!
You’ve indicated that you need to import schema definitions for the namespace http://schemas.xmlsoap.org/soap/encoding/, but you haven’t told the processor where to find these definitions. Try adding (to the xs:import) a schemaLocation attribute that tells the processor where to find a schema document for this namespace.