Unable to find declaration of 'assignments' elements

So, I start with XML and Schemas, and today I came across this and I could not figure it out.

I get an error message

Ln 5 Col 2: Unable to find declaration of assignment elements.

I believe that I declared the item, but maybe I am missing something and I don’t know.

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>

Since I'm still involved, feel free to point out any other errors that I might not have made related to the problem.

Thanks
Levy

+3
source share
3 answers

, "" , - .

, :

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

:

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

, .

+2

. , :

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">        
  <xs:element name="assignments" type="TypeAssignments" />    
  <xs:complexType name="TypeAssignments">
    <xs:sequence>
      <xs:element name="assignment" type="assignmentInfo" 
          minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>        
  </xs:complexType>

  <xs:complexType name="assignmentInfo">
    <xs:sequence>
      <xs:element name="name" type="xs:string" />
      <xs:element name="page" type="TypePage" />
      <xs:element name="files" type="xs:string"  minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required" />
  </xs:complexType>   

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

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

:

  • TypeAssignments assignmentInfo.
  • xs
  • minOccurs maxOccurs . .
  • , "/" > "" " , .

, , .

0

, , xmlns <assignments> . , <assignments> http://www.w3.org/2001/XMLSchema-instance".

However, the schema document says targetNamespace" http://www.levijackson.net/web340/ns ". Because the elements in your document instance do not have this namespace, validation fails.

Start by modifying the instance document to look like this:

<assignments
    xmlns="http://www.levijackson.net/web340/ns"
0
source

Source: https://habr.com/ru/post/1718105/


All Articles