The following is my XML Schema followed by the .xml file that I want to validate against.
I continue to receive the error
Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'type': References from this schema to components in no namespace are not allowed, since not indicated by an import statement.
I am a novice in this area and my understanding of using a namespace is to create "global" types, such as the complex type "OneType" that I am reusing globally.
My Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="test/namespace" targetNamespace="test/namespace"
elementFormDefault="qualified">
<xsd:complexType name="OneType">
<xsd:annotation>
<xsd:documentation>One Test</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element name="One"/>
</xsd:choice>
</xsd:complexType>
<xsd:element name="testroot">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Test" type="OneType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
My XML:
<?xml version="1.0" encoding="UTF-8"?>
<tns:testroot xmlns:tns="test/namespace">
<tns:Test>
<tns:One/>
</tns:Test>
</tns:testroot>
Replace
<xsd:element name="Test" type="OneType"/>
with
<xsd:element name="Test" type="tns:OneType"/>
and then your XSD will have no errors, and your XML will be valid against your XSD.