我想知道你是否可以指出我的架构有什么问题?我已经使用 - http://www.utilities-online.info/xsdvalidation/#.VQkt1BCUfA4检查了我的XML
文档是否格式正确 - 它已经很好地形成了。但是,当我针对我的schema
文档检查xml
时,它会显示大量的错误。我真的不知道自己在架构中做错了什么!如果有人能给我一个很棒的牌。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE grant [
<!ELEMENT grant (title, agency, department, summary, initiated, expires, coordinator)>
<!ATTLIST grant grantNum ID #REQUIRED>
<!ATTLIST grant funding (federal|state|local|private) #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT agency (#PCDATA)>
<!ELEMENT department (#PCDATA)>
<!ELEMENT summary (#PCDATA)>
<!ELEMENT initiated (#PCDATA)>
<!ELEMENT expires (#PCDATA)>
<!ELEMENT coordinator (#PCDATA)>
]>
<grant xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com grant.xsd"
grantNum="NIHCCC-4481-05" funding="federal">
<title>NIH Clinical Cancer Basic Research Grant</title>
<agency>National Institute of Health</agency>
<department>University Hospital Clinical Cancer Center</department>
<summary>
Basic NIH support funding for current and future Phase 1 through Phase 3 cancer
clinical trials.
</summary>
<initiated>2006-07-01</initiated>
<expires>2010-06-30</expires>
<coordinator>Alice Walters</coordinator>
</grant>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- 1. root element for a schema -->
<!-- Elements -->
<xs:element name='agency' type='xs:string' />
<xs:element name='summary' type='xs:string' />
<xs:element name='department' type='xs:string' />
<xs:element name='summary' type='xs:date' />
<xs:element name='initiated' type='xs:date' />
<xs:element name='expires' type='xs:date' />
<xs:element name='coordinator' type='xs:string' />
<!-- Attributes -->
<xs:attribute name='grantNum' type='xs:grantNumFormat' />
<xs:attribute name='funding' type='xs:fundingFormat' />
<!-- Simple Type -->
<xs:simpleType name='grantNumFormat'>
<xs:restriction base='xs:ID'>
<xs:pattern value='Lu(6)-d(4)-d(2)' />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name='fundingFormat'>
<xs:restriction base="xs:string">
<xs:enumeration value="male" />
<xs:enumeration value="female" />
<xs:enumeration value="all" />
</xs:restriction>
</xs:simpleType>
<!-- Complex Type -->
<xs:element name="grant"> <!-- 4. declare the complex type -->
<xs:complexType>
<xs:sequence>
<xs:element ref="agency" />
<xs:element ref="summary" />
<xs:element ref="department" />
<xs:element ref="summary" />
<xs:element ref="initiated" /> <!-- 7. can have many comments -->
<xs:element ref="expires" />
<xs:element ref='coordinator' />
</xs:sequence>
<xs:attribute ref="grantNum" use="required" /> <!-- 6. attribute specify the use -->
<xs:attribute ref="funding" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
如果我的架构错误,请告诉我!
答案 0 :(得分:0)
首先(根据此验证器:http://www.utilities-online.info/xsdvalidation/):您的xs文件格式不正确。你必须声明元素'summary',只需按时声明并在需要时引用它两次。当您使用xsd文件中的自定义类型时,您不能说命名空间中有自定义类型,因此请移除xs:
和type='xs:grantNumFormat'
type='xs:fundingFormat'