Search code examples
xmleclipsexsdxsd-validationxml-validation

Why is XSD validation failing offline but working online?


I have these two files, the XML and XSD.

schedule.xml:

    <?xml version="1.0"?>
    <Schedule xmlns ="schedule"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:noNamespaceSchemaLocation="schedule.xsd">
        <Event>
                <Title>Artificial Intelligence</Title>
                <Lecture>
                    <Day>Wednesday</Day>
                    <Time>09-11</Time>
                </Lecture>
        </Event>
</Schedule>

schedule.xsd:

    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                          targetNamespace="schedule"
                          xmlns="schedule"
                          elementFormDefault="qualified">
        <xsd:element name="Schedule">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="Event"  maxOccurs="unbounded">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="Title" type="xsd:string"/>
                                <xsd:element name="Lecture">
                                    <xsd:complexType>
                                        <xsd:sequence>
                                            <xsd:element name="Day" type="xsd:string"/>
                                            <xsd:element name="Time" type="xsd:string"/>
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>

I use eclipse Neon.1a Release (4.6.1) on MacOS Sierra (10.12.1). When I try to validate the XML file I get the following error:

cvc-elt.1: Cannot find the declaration of element 'Schedule'. schedule.xml /knowledge1 line 4 XML Problem

but if I try to validate it on other PC or online it works. Only if I put the extra line:

xsi:schemaLocation="schedule schedule.xsd"

it works, on my PC. My question is why do I get this error only on my PC? I do not want to fix my files I want to know why I get this error only on my PC.


Solution

  • Read How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

    Pay attention in particular to two points:

    1. Your (incorrect) use of xsi:noNamespaceSchemaLocation on a document that has namespaces does not help any processor associate an XSD with this document.
    2. Online, you're providing more direct specification of the XSD you wish to be used, so the online processor does not need the (incorrect) in-document hint.