1
votes

I try to extend ISOSTS XSD scheme for supporting SVG images tags. I found XSD scheme for SVG and has put it near ISOSTS.xsd. Now I try to extend ISOSTS.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:mml="http://www.w3.org/1998/Math/MathML"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:tbx="urn:iso:std:iso:30042:ed-1"
        xmlns:xlink="http://www.w3.org/1999/xlink"

<!-- my line -->   
        xmlns:svg="http://www.w3.org/2000/svg"

        elementFormDefault="qualified">
      <xs:import namespace="http://www.w3.org/1998/Math/MathML" 
                 schemaLocation="ncbi-mathml2/mathml2.xsd"/>
      <xs:import namespace="http://www.w3.org/1999/xlink" 
                 schemaLocation="xlink.xsd"/>
      <!-- XSD import of namespace http://www.w3.org/2001/XMLSchema-instance suppressed (not necessary) -->
      <xs:import namespace="http://www.w3.org/XML/1998/namespace" 
                 schemaLocation="xml.xsd"/>
      <xs:import namespace="urn:iso:std:iso:30042:ed-1" 
                 schemaLocation="tbx.xsd"/>

<!-- my line -->   
      <xs:import namespace="http://www.w3.org/2000/svg" 
                 schemaLocation="SVG.xsd"/>

....
<xs:element name="p">
  <xs:complexType mixed="true">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
<!-- my line -->   <xs:element ref="svg:svg"/>
                   <xs:element ref="email"/>
....

But I have error when try to load scheme:

    from lxml.etree import parse, XMLSchema

    schema_file = open(self._schema_filename)

    schema_doc = parse(schema_file)
    schema_file.close()

    self._xmlschema = XMLSchema(schema_doc)  # Error

Error message:

File "src/lxml/xmlschema.pxi", line 87, in lxml.etree.XMLSchema.init (src/lxml/lxml.etree.c:197819)

lxml.etree.XMLSchemaParseError: Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': References from this schema to components in the namespace 'http://www.w3.org/2000/svg' are not allowed, since not indicated by an import statement., line 4664

What is wrong?

3

3 Answers

1
votes

The message seems clear enough to me, I'm not sure which part of it you don't understand. Your schema document imports schema components for various namespaces (mathml, xlink, xml, etc) but it makes no attempt to import the schema for SVG, and the error message is telling you so.

1
votes

I replicated your three modifications (declaring a namespace binding for the SVG namespace, importing the SVG namespace, and referring to the svg:svg element), but got no error from Xerces or Saxon EE.

So it seems to me that you've done everything right.

The error message suggests that your XSD validator is not picking up the import.

If I had to guess (and I suppose I have to, since while you've given a very concise statement of the problem, we don't have a reproducible error), your validator is looking at an interim version of the schema document in which the reference to svg:svg has been added to the content model of p, but the xs:import statement has not yet been added to the beginning of the schema document.

Possibly your Python bytecode is out of date and your Python needs to be recompiled? (Pure conjecture; I don't know how much schema information lxml generates at compile time and how much it generates at run time.)

0
votes

Problem solved using next XSD schema for SVG: https://github.com/dumistoklus/svg-xsd-schema