我在XSD验证方面遇到了一些问题,这应该很容易运行。以下是我的XML:
<Configuration>
<Dependencies>
<Dependency name="python"></Dependency>
</Dependencies>
<Plugins>
<Plugin>
<Dependencies>
<Dependency name="python"></Dependency>
</Dependencies>
</Plugin>
</Plugins>
</Configuration>现在是我的架构(请不要在Configuration元素中使用key.keyref对):
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Configuration">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="Dependencies" type="DependenciesType"></xs:element>
<xs:element name="Plugins">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="Plugin" type="PluginType" minOccurs="1" maxOccurs="unbounded"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="kDependency">
<xs:selector xpath="./Dependencies/Dependency"></xs:selector>
<xs:field xpath="@name"></xs:field>
</xs:key>
<xs:keyref name="krPluginDependency" refer="kDependency">
<xs:selector xpath="./Plugins/Plugin/Dependencies/Dependency"></xs:selector>
<xs:field xpath="@name"></xs:field>
</xs:keyref>
</xs:element>
<!-- Now the Dependencies types -->
<xs:complexType name="DependenciesType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="Dependency" type="DependencyType"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DependencyType">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<!-- And the plugin type -->
<xs:complexType name="PluginType">
<xs:sequence>
<xs:element name="Dependencies" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="Dependency" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>插件依赖项名称必须引用配置依赖项名称。我遵循这里的教程,以检查我是否是傻瓜(st5.html)。我检查了我的XPath表达式,它们很好(https://www.freeformatter.com/xpath-tester.html)。
当我试图验证我的XML文件时:
键'krPluginDependency‘和值'python’没有找到元素‘配置’的标识约束。
我不知道问题出在哪里。
发布于 2017-07-08 12:18:17
好吧,这真是个荒谬的错误。在PluginType Dependency类型中,属性name需要一个类型。在我的例子中,它是type="xs:string",工作正常。
https://stackoverflow.com/questions/44981203
复制相似问题