找不到元素“赋值"的声明 [英] Cannot find the declaration of element 'assignments'

查看:45
本文介绍了找不到元素“赋值"的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从 XML 和 Schemas 开始,今天我遇到了这个问题,但我一直无法弄清楚.

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

我收到错误提示,

Ln 5 Col 2:找不到元素赋值"的声明.

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.

这是我的 XML 文件:

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>

这是我的架构文件:

<?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.

谢谢
列维

推荐答案

这个问题的解决方案是我没有将我的主要元素'赋值'声明为一个复杂元素,我实际上不是't 将其声明为任何东西.

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>

并将其更改为:

<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.

李维

这篇关于找不到元素“赋值"的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆