XML Schema validator error on attribute declaration

那年仲夏 提交于 2019-12-13 03:35:45

问题


I get an error on validation:

Error - Line 14, 36: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 36; s4s-elt-must-match.1: The content of 'simpleType' must match (annotation?, (restriction | list | union)). A problem was found starting at: attribute.

How to resolve it?

My XML fragment

<CHANEL_NAME lang="RUS/MD">N4</CHANEL_NAME>

And XSD:

<xs:element name="CHANEL_NAME">
    <xs:simpleType>
         <xs:restriction base="xs:string">
            <xs:length value="40"/>
        </xs:restriction>
        <xs:attribute name="lang">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="MD"/>
                    <xs:enumeration value="RUS"/>
                    <xs:enumeration value="RUS/MD"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:simpleType>
</xs:element>

So I need in attribute 'lang' only determined values like 'MD', 'RUS' or 'RUS/MD'. I read examples and I guess it's OK.

Or is enumeration only for elements and not for attributes?


回答1:


The problem is the first simpleType. Simple types can't have attribute.

You probably need a complex type with simple content. Something like:

<xs:element name="CHANEL_NAME">
  <xs:complexType>
    <xs:simpleContent>
      <xs:restriction base="xs:string">
       <xs:length value="40"/>
       <xs:attribute name="lang">
         <xs:simpleType>
           <xs:restriction base="xs:string">
             <xs:enumeration value="MD"/>
             <xs:enumeration value="RUS"/>
             <xs:enumeration value="RUS/MD"/>
           </xs:restriction>
         </xs:simpleType>
       </xs:attribute>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

(Not tested.)

Also consider naming your anonymous types.

ps. Also consider using/restricting xs:language as language type.

Всего наилучшего.



来源:https://stackoverflow.com/questions/26991135/xml-schema-validator-error-on-attribute-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!