我有幾個xml文件,但我只出現一個xsd,並對其進行驗證。首先讓我描述這個問題。我編輯VS2010中的文件,並且在編輯xml文件時,VS運行時解析器顯示沒有錯誤。 DOM文檔:: schemaValidate():元素「元素」:後來,當我運行它加載XML文件並驗證它針對XML模式的PHP命令行腳本,它與excption說對xml架構的Xml驗證在php中失敗,但在.NET(VS2010)中起作用
警告沒有結束比賽爲keyref'elementRef'的鍵序列['回答']找到。
但是,我真的不能在xsd文件中看到一個錯誤。
XML文件:在XSD文件
<domain xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Answer" namespace="Custom\Surveys" xsi:noNamespaceSchemaLocation="../../xsd/domain.xsd">
<entities>
<entity name="Answer" main="true" schema="answers"/>
</entities>
<bindings>
</bindings>
<key>
<element entity="answers" property="question_option_id"/>
<element entity="answers" property="survey_voter_id"/>
</key>
</domain>
XML模式:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="domain">
<xs:complexType>
<xs:sequence>
<xs:element name="entities">
<xs:complexType>
<xs:sequence>
<xs:element name="entity" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" id="entityName" />
<xs:attribute name="main" type="xs:boolean" use="optional" default="false" />
<xs:attribute name="schema" type="xs:string" use="required" id="schemaName" />
</xs:complexType>
</xs:element>
<xs:element name="multientity" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="schema" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="bindings" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="bind" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="referenced">
<xs:complexType>
<xs:attribute name="entity" type="xs:string" use="required" />
<xs:attribute name="property" type="xs:string" use="required" />
</xs:complexType>
<xs:keyref name="referencedRef" refer="entityId">
<xs:selector xpath="." />
<xs:field xpath="@entity" />
</xs:keyref>
</xs:element>
</xs:sequence>
<xs:attribute name="entity" type="xs:string" use="required" />
<xs:attribute name="property" type="xs:string" use="required" />
</xs:complexType>
<xs:keyref name="bindRef" refer="entityId">
<xs:selector xpath="." />
<xs:field xpath="@entity" />
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="key">
<xs:complexType>
<xs:sequence>
<xs:element name="element" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="entity" type="xs:string" use="required" />
<xs:attribute name="property" type="xs:string" use="required" />
</xs:complexType>
<xs:keyref name="elementRef" refer="entityId">
<xs:selector xpath="." />
<xs:field xpath="@entity" />
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="namespace" type="xs:string" use="required" />
</xs:complexType>
<xs:key name="entityId">
<xs:selector xpath="./entities/entity|./entities/multientity" />
<xs:field xpath="@schema" />
</xs:key>
</xs:element>
</xs:schema>
您是否添加了適當的標題到您的XML文件? '<?xml version =「1.0」encoding =「utf-8」?>' – 2012-07-24 14:10:08
好的,但是我做到了。 – Santhos 2012-07-24 14:17:35