1

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
duke2311
  • 85
  • 7
  • I suspect that your xml file is confusing. You state that the namespace for the file is `schedule` and then you provide the link `xsi:noNamespaceSchemaLocation="schedule.xsd"`. You should research what defining a namespace mans. – Bob Dalgleish Nov 02 '16 at 14:29

1 Answers1

1

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.
Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • as I understood the main problem is that when I do not state the location that the namespace is the varidator could not link it, with the default namespace (xmlns), for some reason. Contrary if I state where the file is located or if I state a name to the namespace, for example xmlns:p it works – duke2311 Nov 05 '16 at 13:00