Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find the declaration of element 'assignments'

Tags:

xml

schema

So I am beginning with XML and Schemas and I ran across this today and I have not been able to figure it out.

I am getting and error that says,

Ln 5 Col 2 : Cannot find the declaration of element 'assignments'.

I believe I have declared the element, but perhaps I am missing something and have not.

This is my XML file:

<?xml version="1.0" encoding="UTF-8"?>
<assignments
    xmlns="http://www.w3.org/2001/XMLSchema-instance"
    SchemaLocation="A3.xsd"
>
    <assignment id="a1">
        <name>Schemas</name>
        <page>110</page>
    </assignment>

    <assignment id="a2">
        <name>Namespaces</name>
        <page>258</page>
        <files>names.xml</files>
        <files>names.dtd</files>
    </assignment>

    <assignment id="a3">
        <name>RELAX NG</name>
        <page>305</page>
        <files>account.xml</files>
        <files>customers.xml</files>
        <files>finance.xsd</files>
    </assignment>

</assignments>

This is my Schema file:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema" 
    xmlns:target="http://www.levijackson.net/web340/ns" 
    targetNamespace="http://www.levijackson.net/web340/ns" elementFormDefault="qualified"
>
<element name="assignments" type="target:TypeAssignments"></element>

<complexType name="TypeAssignments">
    <sequence>
        <element name="assignment" type="target:assignmentInfo"></element>
    </sequence>
    <attribute name="id" type="string" use="required"/>
</complexType>

<complexType name="assignmentInfo">
    <sequence>
            <element name="name" type="string"></element>
            <element name="page" type="target:TypePage"></element>
            <element name="file" type="target:TypeFile" minOccurs="0" maxOccurs="unbounded"></element>
    </sequence>
</complexType>

<simpleType name="TypePage">
    <restriction base="integer">
        <minInclusive value="50" />
        <maxInclusive value="498" />
    </restriction>
</simpleType>

<simpleType name="TypeFile">
    <restriction base="string">
        <enumeration value=".xml" />
        <enumeration value=".dtd" />
        <enumeration value=".xsd" />
    </restriction>
</simpleType>

</schema>

As I am still learning, feel free to point out any other mistakes I may have made not related to the problem.

Thanks
Levi

like image 753
Levi Avatar asked Dec 31 '25 16:12

Levi


1 Answers

The solution to this problem was that I was not declaring my main element 'assignments' as a complex element, I actually wasn't declaring it as anything at all.

So by taking this line from my schema file:

<element name="assignment" type="target:assignmentInfo" minOccurs="0" maxOccurs="unbounded"></element>

and changing it into this:

<element name="assignments">
    <complexType>
        <sequence>
            <element name="assignment" type="target:assignmentInfo" minOccurs="0" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
</element>

The element was properly defined, thanks for the help everyone.

Levi

like image 150
Levi Avatar answered Jan 03 '26 12:01

Levi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!