属性声明中的 XML 架构验证器错误 [英] XML Schema validator error on attribute declaration

查看:21
本文介绍了属性声明中的 XML 架构验证器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在验证时遇到错误:

错误 - 第 14、36 行:org.xml.sax.SAXParseException;行号:14;列数:36;s4s-elt-must-match.1:'simpleType' 的内容必须匹配(注释?,(限制|列表|联合)).从以下位置开始发现问题:属性.

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.

如何解决?

我的 XML 片段

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

和 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>

所以我只需要在属性 'lang' 中确定诸如 'MD'、'RUS' 或 'RUS/MD' 之类的值.我阅读了示例,我想这没问题.

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?

推荐答案

问题出在第一个simpleType.简单类型不能有属性.

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>

(未测试.)

还要考虑命名您的匿名类型.

Also consider naming your anonymous types.

ps.还可以考虑使用/限制 xs:language 作为语言类型.

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

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

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

这篇关于属性声明中的 XML 架构验证器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆