2014-01-05 2 views
0

Работа с eclipse Я избавился от всех ошибок, но когда я изменяю содержимое элемента в своем документе xml, за исключением ограничений, установленных в файле .xsd, ошибки проверки не отображаются. Я пробовал проверить его в сети с помощью http://www.freeformatter.com/xml-validator-xsd.html, и я получаю сообщение об ошибке «Cvc-elt.1: не удается найти декларацию элемента« DatabaseInventory ».. Строка« 4 », столбец« 69 », но в eclipse он проверяет штраф. Не уверен, что я сделал неправильно.xml document not validating to xsd schema

Это мой 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> 

ответ

1

В этом случае затмение не выполняет проверку, так как она не может связать схему с документом экземпляра.

Во-первых, ваша схема не определяет целевое пространство имен, что означает, что ваш экземпляр документа должен не объявить пространство имен по умолчанию:

<DatabaseInventory xmlns="http://www.w3schools.com" > 

Изменение, что в:

<DatabaseInventory > 

Во-вторых, атрибут xsi:schemaLocation принимает список пар {URI, URL}, где URI - это URI пространства имен и URL-адрес местоположения соответствующей схемы. Однако, поскольку ваша схема не объявляет целевое пространство имен, вместо этого вы должны использовать атрибут xsi:noNamespaceSchemaLocation. Ваш первый элемент должен выглядеть так:

<DatabaseInventory 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="DatabaseInventory.xsd"> 
0

У вас есть две вещи неправильно. 1. -Вы это в схеме:

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

И это в XML:

<OracleSID>Productio</OracleSID> 

и должен быть

<OracleSID>Production</OracleSID> 

, который является одним из допустимых значений.

2.- Вы имеете этот элемент в вашем XML:

<Administrator EmailAlias="jhunter" Extension="6007"> 

но не определен в вашей XSD. Может быть, вы хотите использовать этот другой элемент:

<xs:element name="Administrator-type" type="Administrator-type" minOccurs="1" maxOccurs="3"/> 

Таким образом, вы должны заменить это:

<Administrator EmailAlias="jhunter" Extension="6007"> 
     Jeffrey Hunter 
    </Administrator> 

с этим

<Administrator-type EmailAlias="jhunter" Extension="6007"> 
     Jeffrey Hunter 
    </Administrator-type>