I am working on a very basic XML schema and I am receiving
cvc-type.3.1.2: Element 'creator' is a simple type, so it must have no element information item [children]. [8]
in NetBeans when I attempt to validate XML. I am following the W3 schools tutorial and it seems my code is very similar to theirs. I am confused how the error states creator is a simple type when I declared it as complex. Did I incorrectly declare the creator element as a complex type?
XML doc:
<?xml version="1.0" encoding="UTF-8" ?>
<gallery
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Proj1Schema.xsd">
<creator>
<name>John Doe</name>
</creator>
</gallery>
Schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://xml.netbeans.org/schema/gallery"
elementFormDefault="qualified">
<xs:element name="creator">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="gallery">
<xs:complexType>
<xs:sequence>
<xs:element name="creator" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Replace
<xs:element name="creator" type="xs:string"/>
with
<xs:element ref="creator"/>
to reuse the global declaration of element
within the content model of gallery
. As you had the XSD, creator
within gallery
would only allow simple xs:string
content, contrary to your XML which has complex content, including a name
child element.