我有一个xsd,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/api/2.2" elementFormDefault="qualified" version="1.0" xml:lang="EN" targetNamespace="http://www.example.com/api/2.2">
<xs:element name="configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="domain" type="domain"/> <!-- changed here -->
</xs:sequence>
<xs:attribute name="timestamp" type="xs:normalizedString" use="optional"/>
<xs:attribute name="version" type="xs:token" fixed="2.2"/>
</xs:complexType>
</xs:element>
<xs:complexType name="domain"> <!-- and here -->
<xs:sequence>
<xs:any minOccurs="0"/>
</xs:sequence>
<xs:attribute name="account" type="uid" use="required">
</xs:attribute>
</xs:complexType>
<xs:simpleType name="uid">
<xs:restriction base="xs:string">
<xs:length value="36"/>
<xs:pattern value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
并且通过一个在线xsd到xml生成器生成的xml就像这样
<?xml version="1.0" encoding="utf-8"?>
<configuration timestamp="str111" version="2.2">
<domain account="str123400000000000000000000000000000" />
</configuration>
但是当我要通过javax.xml.validation.Validator进行验证时,它会抛出异常
Error: cvc-elt.1: Cannot find the declaration of element 'configuration'.; ;130503155804008299000002; ; WebContainer : 2;
和这个
<COMMONS_ERROR>; ErrorThe Exception occured at Line No.1 Column No.107; ; 130503155804008299000002; ; WebContainer : 2;
请帮助我......找出适合上述xsd的正确xml模式
答案 0 :(得分:0)
您的架构定义了命名空间http://www.example.com/api/2.2
发电机似乎忽略了这一点。
在xml中向xmlns="http://www.example.com/api/2.2"
添加名称空间声明configuration
,一切都会好的。