我是XML Schema的新手,目前正在跟进它。以下问题来自其中一项任务。该任务是为我们之前必须制作的XML文档之一设置XML Schema文档。 XML Document看起来像这样:
<? xml version="1.0" encoding="UTF-8" ?>
<CPBISchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ds.arch.tue.nl/7m900/assignment/cpbischema"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://ds.arch.tue.nl/7m900/assignment/cpbischema
Assignment 2.2a 7M900 NAM van de Ven.xsd">
<person id="p1">
<login>N.Johnston</login>
<password>johnston1508</password>
<name>Nicholas F. Johnston</name>
<address>199, 51st Street</address>
<city>New Orleans</city>
<email>n.johnston@cpbi.com</email>
<Ref_person.requirements requirements="r2" />
<Ref_person.collective />
</person>
<!-- etc. -->
<collective id="c1">
<homepage href="http://www.bam.nl/" />
<description>Koninklijke BAM groep nv</description>
<active>yes</active>
<Ref_collective.person person="p1"/>
<Ref_collective.person_ManagedBy person="p2"/>
<Ref_collective.requirements requirements="r1"/>
</collective>
<!-- etc. -->
</CPBISchema>
使用以下XML Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xlink="http://www.w3.org/1999/xlink"
targetNamespace="http://ds.arch.tue.nl/7m900/assignment/cpbischema"
elementFormDefault="qualified">
<xsd:import namespace="http://www.w3.org/1999/xlink"
schemaLocation="xlink.xsd"/>
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>
<xsd:complexType name="CPBISchema">
<xsd:sequence>
<xsd:element name="person" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="collective" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="requirements" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="spacerequirements" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="dwelling" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="space" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="CPBISchema" type="CPBISchema" />
<xsd:complexType name="Person">
<xsd:sequence>
<xsd:element name="login" type="xsd:string" />
<xsd:element name="password">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-z]+/d{4}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="address" type="xsd:string" />
<xsd:element name="city" type="xsd:string" />
<xsd:element name="email" type="xsd:string" />
<xsd:element name="Ref_person.requirements">
<xsd:complexType>
<xsd:attribute name="requirements" type="xsd:IDREF" use="required" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Ref_person.collective" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="collective" type="xsd:IDREF" use="optional" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required" />
</xsd:complexType>
<xsd:element name="person" type="Person" />
<xsd:complexType name="Collective">
<xsd:sequence>
<xsd:element name="homepage">
<xsd:complexType>
<xsd:attributeGroup ref="xlink:simpleLink" />
</xsd:complexType>
</xsd:element>
<xsd:element name="description" type="xsd:string" />
<xsd:element name="active" type="xsd:boolean" />
<xsd:element name="Ref_collective.person" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="person" type="xsd:IDREF" use="optional" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Ref_collective.person_ManagedBy">
<xsd:complexType>
<xsd:attribute name="person" type="xsd:IDREF" use="required" />
</xsd:complexType>
</xsd:element>
<xsd:element name="Ref_collective.requirements">
<xsd:complexType>
<xsd:attribute name="requirements" type="xsd:IDREF" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="required" />
</xsd:complexType>
<xsd:element name="collective" type="Collective" />
</xsd:schema>
在验证XML Schema的XML Document时 - 就像赋值一样 - NetBeans(我使用的程序)给出了以下错误消息: schema_reference.4:无法读取模式文档'Assignment',因为1)找不到文档; 2)文件无法阅读; 3)文档的根元素不是。
我的猜测是我没有以正确的方式宣布架构文档,但错误的确切位置我不知道。我做错了什么?
答案 0 :(得分:1)
正确的XSD是..
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xlink="http://www.w3.org/1999/xlink"
targetNamespace="http://ds.arch.tue.nl/7m900/assignment/cpbischema"
xmlns="http://ds.arch.tue.nl/7m900/assignment/cpbischema"
elementFormDefault="qualified">
正确的XML是..
<CPBISchema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ds.arch.tue.nl/7m900/assignment/cpbischema"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://ds.arch.tue.nl/7m900/assignment/cpbischema
Assignment2.2a7M900NAMvandeVen.xsd
http://www.w3.org/1999/xlink xlink.xsd">
您必须重命名Assignment 2.2a 7M900 NAM van de Ven.xsd
中的XSD Assignment2.2a7M900NAMvandeVen.xsd
,因为使用schemaLocation
时空格有问题。
您必须添加schemaLocation xlink.xsd
声明。
See this reference to use of schemaLocation
此属性有两个值,以空格分隔。第一个值 是要使用的命名空间。第二个值是XML的位置 用于该命名空间的模式:
xsi:schemaLocation =&#34; http://www.w3schools.com note.xsd&#34;