使用eclipse我已經擺脫了所有錯誤,但是當我更改xml文檔中的元素內容超出了.xsd文件中設置的限制時,不會出現驗證錯誤。我試過用http://www.freeformatter.com/xml-validator-xsd.html在線驗證它,我得到錯誤「Cvc-elt.1:找不到元素'DatabaseInventory'的聲明'。'行'4,列'69'」但在日食它驗證罰款。不知道我做錯了什麼。xml文檔未驗證到xsd模式
這是我的XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- standalone is no as this doc references external schema -->
<DatabaseInventory xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="DatabaseInventory.xsd">
<!-- tried to include "http://www.w3schools.com" alongside "DatabaseInventory.xsd" but wouldn't validate -->
<!-- default name space declaration -->
<!-- declare XML Schema Instance namespace, so schemaLocation attribute can be called -->
<!-- declare SYSTEM schema to use for this namespace "DatabaseInventory.xsd -->
<DatabaseName>
<GlobalDatabaseName>production.iDevelopment.info</GlobalDatabaseName>
<OracleSID>Productio</OracleSID>
<DatabaseDomain>iDevelopment.info</DatabaseDomain>
<Administrator EmailAlias="jhunter" Extension="6007">
Jeffrey Hunter
</Administrator>
<DatabaseAttributes Type="Production" Version="9i"/>
<Comments>
The following database should be considered the most stable for up-to-date
data. The backup strategy includes running the database in Archive Log Mode
and performing nightly backups. All new accounts need to be approved by the
DBA Group before being created.
</Comments>
</DatabaseName>
<DatabaseName>
<GlobalDatabaseName>development.iDevelopment.info</GlobalDatabaseName>
<OracleSID>Development</OracleSID>
<DatabaseDomain>iDevelopment.info</DatabaseDomain>
<Administrator EmailAlias="jhunter" Extension="6007">
Jeffrey Hunter
</Administrator>
<Administrator EmailAlias="mhunter" Extension="6008">
Melody Hunter
</Administrator>
<DatabaseAttributes Type="Development" Version="9i"/>
<Comments>
The following database should contain all hosted applications. Production
data will be exported on a weekly basis to ensure all development environments
have stable and current data.
</Comments>
</DatabaseName>
<DatabaseName>
<GlobalDatabaseName>testing.iDevelopment.info</GlobalDatabaseName>
<OracleSID>Testing</OracleSID>
<DatabaseDomain>iDevelopment.info</DatabaseDomain>
<Administrator EmailAlias="jhunter" Extension="6007">
Jeffrey Hunter
</Administrator>
<Administrator EmailAlias="mhunter" Extension="6008">
Melody Hunter
</Administrator>
<Administrator EmailAlias="ahunter">
Alex Hunter
</Administrator>
<DatabaseAttributes Type="Testing" Version="9i"/>
<Comments>
The following database will host more than half of the testing for our hosting
environment.
</Comments>
</DatabaseName>
</DatabaseInventory>
這是架構
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- using Venetian blinds layout, s3346141 - 1 mod 3 = 1 -->
<xs:complexType name="DatabaseAttributes-type">
<xs:attribute name="Type" type="restricted-Type-values" use="required"/>
<xs:attribute name="Version" type="restricted-Version-values" default="9i"/>
<!-- set default value for Version -->
</xs:complexType>
<xs:simpleType name="restricted-Extention-values">
<xs:restriction base="xs:integer">
<xs:pattern value="6[0-9][0-9][0-9]"/>
<!-- set REGEX for first digit = 6 followed by 3 digits -->
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="restricted-Type-values">
<xs:restriction base="xs:string">
<xs:enumeration value="Production"/>
<xs:enumeration value="Development"/>
<xs:enumeration value="Testing"/>
<!-- converted enumerated list into discrete values-->
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="restricted-Version-values">
<xs:restriction base="xs:string">
<xs:enumeration value="7"/>
<xs:enumeration value="8"/>
<xs:enumeration value="8i"/>
<xs:enumeration value="9i"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="max-string-type">
<xs:restriction base="xs:string">
<xs:maxLength value="300"/>
<!-- increased char length to 300 to enable validation of DatabaseInventory.xml -->
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Administrator-type">
<!-- felt I needed to discriminate a name difference between element names and repeated types to make code clearer -->
<xs:attribute name="EmailAlias" type="xs:string" use = "required"/>
<xs:attribute name="Extension" type="restricted-Extention-values" use = "optional"/>
</xs:complexType>
<xs:complexType name="DatabaseName-type">
<xs:sequence>
<xs:element name="GlobalDatabaseName" type="xs:string" />
<xs:element name="OracleSID" type="restricted-Type-values" />
<xs:element name="DatabaseDomain" type="xs:string" />
<xs:element name="Administrator-type" type="Administrator-type" minOccurs="1" maxOccurs="3"/>
<xs:element name="DatabaseAttributes" type="DatabaseAttributes-type" />
<xs:element name="Comments" type="max-string-type" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="DatabaseInventory-type">
<xs:sequence>
<xs:element name="DatabaseName" type="DatabaseName-type" minOccurs="1" maxOccurs="unbounded"/>
<!-- set databaseName element to occur 1 or more times -->
</xs:sequence>
</xs:complexType>
<xs:element name="DatabaseInventory" type="DatabaseInventory-type" />
<!-- set root element to link to DatabaseInventory-type -->
</xs:schema>