2014-03-26 130 views
0

我试图写这几行XML模式:XML Schema的验证问题

<place id = "1234"> 
    <placeName lang = "de" type = "std"> SOMENAME <gender> n </gender> </placeName> 
</place> 

架构如下:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
<xs:element name="place"> 
    <xs:complexType > 
    <xs:complexContent> 
     <xs:restriction base="xs:anyType"> 

      <xs:sequence> 
      <xs:element name= "placeName"> 
       <xs:complexType> 
       <xs:simpleContent> 
        <xs:extension base="xs:string"> 

         <xs:sequence> 
         <xs:element name= "gender" type= "xs:string"/> 

         </xs:sequence>  
         <xs:attribute name= "lang" type= "xs:string" /> 
         <xs:attribute name= "type" type= "xs:string" />    
        </xs:extension> 

       </xs:simpleContent> 
       </xs:complexType> 
      </xs:element> 
      </xs:sequence> 
     <xs:attribute name="id" type="xs:string" /> 
     </xs:restriction> 
     </xs:complexContent> 
    </xs:complexType> 
    </xs:element> 
    </xs:schema> 

我不断收到此错误:E [Xerces的] s4s-elt-invalid-content.1:'#AnonType_placeNameplace'的内容无效。元素“序列”无效,放错位置或发生频率过高。 “序列”是第二个,“性别”标签。


后我做了一些改变:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 
<xs:element name="place"> 
    <xs:complexType > 
    <xs:complexContent mixed = "true"> 
     <xs:extension base="xs:anyType"> 

      <xs:sequence> 
      <xs:element name= "placeName"> 
       <xs:complexType> 
       <xs:complexContent mixed= "true"> 
        <xs:extension base="xs:anyType"> 

         <xs:sequence> 
         <xs:element name= "gender" type= "xs:string"/> 

         </xs:sequence>  
         <xs:attribute name= "lang" type= "xs:string" /> 
         <xs:attribute name= "type" type= "xs:string" />    
        </xs:extension> 

       </xs:complexContent> 
       </xs:complexType> 
      </xs:element> 
      </xs:sequence> 
    <xs:attribute name="id" type="xs:string" /> 
     </xs:extension> 
    </xs:complexContent> 
    </xs:complexType> 
</xs:element> 
</xs:schema> 

我继续接收此错误:COS-nonambig:地名与WC [##任何](或从它们的取代基的元素)违反“唯一粒子归因“。在根据该模式验证,不确定性会为这两个粒子

+0

问题已关闭,谢谢大家!我发现这个神奇的工具:http://www.freeformatter.com/xsd-generator.html我的问题是,我不能指定“字符串”(SOMENAME)如果节点(placeName)已经包含属性字符串和子模式,串。但根据上面的xml-xsd转换器,我甚至不需要指定节点包含文本字符串。大! – user3241376

回答

1

您不能sequencesimpleContent而创建的,我怀疑你真正想要的是使用complexContent却使类型mixed="true"

+0

谢谢!我按照你的说法改变了它,并将“混合”添加到地方的节点。我编辑了这个问题。现在我有另一个错误,但整体看起来更好 - 现在当我可视化模式时,所有节点和属性都存在。 – user3241376

1

扩展xs:anyType不起作用。这是说“你可以有任何序列的元素,其次是地名”。这在本质上是无法预测的,因为当你找到一个地名时,你不知道它是否是“任何元素序列”的一部分,或者是最终的地名。

顺便说一下,请不要以这种方式编辑您的问题,将其变成完全不同的问题。这使得无法理解现有的答案。

+0

如果我把“xs:string”而不是anyType,我仍然得到错误,这次是另一个:[Xerces] src-ct.1:类型'#AnonType_place'的复杂类型定义表示错误。何时使用,基本类型必须是complexType。 'string'是一个simpleType。 – user3241376

+0

问题是重新编辑的,现在它包含代码的初始版本 – user3241376

+0

这完全不清楚为什么你想通过限制或扩展来定义你的类型。为什么不把它定义为“从头”? –