XML架构& xml文档未验证

时间:2015-03-18 08:24:14

标签: xml xsd schema xsd-validation xmlschemaset

我想知道你是否可以指出我的架构有什么问题?我已经使用 - http://www.utilities-online.info/xsdvalidation/#.VQkt1BCUfA4检查了我的XML文档是否格式正确 - 它已经很好地形成了。但是,当我针对我的schema文档检查xml时,它会显示大量的错误。我真的不知道自己在架构中做错了什么!如果有人能给我一个很棒的牌。

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

grant.xsd文件:

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

如果我的架构错误,请告诉我!

1 个答案:

答案 0 :(得分:0)

首先(根据此验证器:http://www.utilities-online.info/xsdvalidation/):您的xs文件格式不正确。你必须声明元素'summary',只需按时声明并在需要时引用它两次。当您使用xsd文件中的自定义类型时,您不能说命名空间中有自定义类型,因此请移除xs:type='xs:grantNumFormat'

中的type='xs:fundingFormat'
相关问题