I’m trying to link an XSD file to an XML file. During validation, I keep getting the same error: Line 3 Column 167 : cvc-elt.1: Cannot find the declaration of element ‘SecondQ’.
I’m using: http://xmlvalidator.new-studio.org/ to validate the documents.
I also noticed that this is a commonly posted issue, but I haven’t been able to solve my situation by reading those other posts.
The two files are in the same folder and there is no website for the domain, just two files locally.
XML DOCUMENT:
<SecondQ xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema q2x.xsd">
<Medicine MID="60004">
<MedicineName>Thorazin</MedicineName>
<MedicineDetails>
<Manufacturer>Pfiezer</Manufacturer>
<Strength>200</Strength>
<PatientMedInfo>
<RefillLeft>3</RefillLeft>
<Repetition>1</Repetition>
<Duration>30</Duration>
</PatientMedInfo>
</MedicineDetails>
</Medicine>
<Medicine MID="60005">
<MedicineName>Ciprodex</MedicineName>
<MedicineDetails>
<Manufacturer>Alcon Laboratories Inc.</Manufacturer>
<Strength>6</Strength>
<PatientMedInfo>
<RefillLeft>1</RefillLeft>
<Repetition>3</Repetition>
<Duration>21</Duration>
</PatientMedInfo>
</MedicineDetails>
</Medicine>
</SecondQ>
XSD DOCUMENT:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="SecondQ">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Medicine" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MedicineName" type="xsd:string"/>
<xsd:element name="MedicineDetails">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Manufacturer" type="xsd:string"/>
<xsd:element name="Strength" type="xsd:integer"/>
<xsd:element name="PatientMedInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RefillLeft" type="xsd:integer"/>
<xsd:element name="Repetition" type="xsd:integer"/>
<xsd:element name="Duration" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="MID" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Thanks in advance.
Assuming your XSD is the “good” one, then you have a couple of issues to fix in your XML:
xmlns="http://www.w3.org/2001/XMLSchema"; your XSD has no target namespace declared, your XML document element should be unqualified.xsi:schemaLocation="http://www.w3.org/2001/XMLSchema q2x.xsd"toxsi:noNamespaceSchemaLocation="q2x.xsd"