For reference, here is your XSD with the types of category
and SimplePatternExpression
stubbed out to be complete:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://alicebot.org/2001/AIML-1.0.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sch="http://www.ascc.net/xml/schematron"
targetNamespace="http://alicebot.org/2001/AIML-1.0.1"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0"
xml:lang="EN">
<xs:element name="aiml">
<xs:annotation>
<xs:documentation>An AIML object is represented by an aiml element in an XML document.</xs:documentation>
<xs:appinfo>
<sch:title>Schematron validation</sch:title>
<sch:ns prefix="aiml" uri="http://alicebot.org/2001/AIML-1.0.1"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="topic">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="category" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="category" type="xs:string"/>
</xs:choice>
<xs:attribute name="version" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1.0.1"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Validating your simplest XML:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1">
<category/>
</aiml>
(assuming no external tie to an XSD) will yield an error such as
[Error] try.xml:2:21: cvc-elt.1.a: Cannot find the declaration of element 'aiml'.
because the parser never located the XSD.
Validating your simplest XML with the XSD location properly hinted at via xsi:noNamespaceSchemaLocation
:
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="try.xsd">
<category/>
</aiml>
will yield an error such as
[Error] try.xsd:10:26: TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of 'http://alicebot.org/2001/AIML-1.0.1'.
[Error] try.xml:4:47: cvc-elt.1.a: Cannot find the declaration of element 'aiml'.
Now the error is because the parser has found the XSD, and the XSD states via targetNamespace
that the aiml
element is expected to be in the http://alicebot.org/2001/AIML-1.0.1
namespace.
At this point, you have to decide whether your intent is to conform to the XSD, which is insisting that the elements of the XML instance be in a namespace, or your intent is to modify the XSD so that your simpler XML instance is valid.
To modify the XSD to eliminate the namespace requirement on the XML:
To allow your XML to be valid without being in a namespace, delete the targetNamespace="http://alicebot.org/2001/AIML-1.0.1"
attribute from the xs:schema
element in the XSD.
To conform to the XSD:
To place the elements of your XML into the namespace required by the XSD, modify the XML as follows:
<?xml version="1.0" encoding="UTF-8"?>
<a:aiml version="1.0.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://alicebot.org/2001/AIML-1.0.1"
xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1 try.xsd">
<a:category/>
</a:aiml>
Note the declaration of a
as a namespace prefix for the http://alicebot.org/2001/AIML-1.0.1
namespace and the use of that prefix on the aiml
and category
elements. Note also the specification of the XSD for the http://alicebot.org/2001/AIML-1.0.1
namespace via the xsi:schemaLocation
attribute.