2013-05-03 59 views
0

我有一个XSD如下XSD到XML转换是不正确的

<?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中验证它throwsfollowing例外

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

你的架构命名空间http://www.example.com/api/2.2

发电机似乎已经忽略了中定义的元素。

在xml中添加名称空间声明xmlns="http://www.example.com/api/2.2"configuration,一切都会好的。

+0

感谢您的帮助 – 2013-05-03 12:34:56