2013-05-03 83 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