1

I created an XSD with the following header.

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="https://github.com/geryxyz/binary-schema"
    targetNamespace="https://github.com/geryxyz/binary-schema"
>
    <xsd:complexType name="formatType">
        <xsd:annotation>
            <xsd:documentation xml:lang="en">
                The root element for the binary file format specification.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="type" type="typeType" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

...

I also created a sample XML based on the above XSD.

<?xml version="1.0" encoding="UTF-8" ?>
<format xmlns="https://github.com/geryxyz/binary-schema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://github.com/geryxyz/binary-schema binary-schema.xsd">
    <type name="sdfsd">
        <chunk length="23"/>
    </type>
</format>

My investigations suggested that the usage of xmlns and targetNamespace in the XSD is somewhat redundant.

I use PyCharm as an IDE, which reports an error in the sample XML file.

enter image description here

The error disappears if I remove the xmlns declaration from the XSD. I would like to understand the underlying concept behind what happened. Is it a bug in PyCharm, or is it an XSD bad practice?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
geryxyz
  • 129
  • 5

1 Answers1

2

No, using targetNamespace and xmlns together is not an error in and of itself.

And, no, removing the default namespace declaration (xmlns) from the XSD will not resolve the error1 – without further adjustment, it will only create an error in the XSD because the referenced type declarations will no longer be found.

The simplest way to resolve your problem would be to add

elementFormDefault="qualified"

to the xsd:schema element of your XSD.

See also


1 If the error appears to go away from this action without raising another error, then it may be a configuration issue, user error of some sort, or a problem/limitation of PyCharm.

kjhughes
  • 106,133
  • 27
  • 181
  • 240