我有几个 xml 文件,但我将只展示一个和我验证它的 xsd。让我首先描述一下这个问题。我在 VS2010 中编辑文件,VS 运行时解析器在编辑 xml 文件时没有显示错误。然后,当我运行一个加载 xml 文件并根据 xml 模式验证它的 php 命令行脚本时,它以一个 excption 结尾
警告:DOMDocument::schemaValidate(): 元素“元素”:没有为 keyref 'elementRef' 的键序列 ['answers'] 找到匹配项。
但是,我真的看不到 xsd 文件中的错误。
xml文件:
<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>
xsd 文件中的 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>