混合类型 XSD 验证帮助

发布于 2024-09-10 17:48:24 字数 619 浏览 5 评论 0原文

我的任务是构建一个 XSD 来验证给定的 xml,我的问题是,一些 XML 元素的形式是

<ElementName description="i am an element">1234567</ElementName>

我构建验证元素“值”而不是属性的 XSD 所需的形式,因此我的经验非常有限在构建 XSD 时(我读过 W3C 教程),我尝试了这个

<xs:element name ="ElementName" type="xs:int">
    <xs:complexType mixed="true">
         <xs:attribute name="description" type="xs:string"/>
    </xs:complexType>
</xs:element>

,你瞧……它不起作用,它说:

“Type 属性不能与 simpleType 或 complexType 一起出现”

我确信我做了一些愚蠢的事情,但在其他地方找不到答案/误解的答案!

提前致谢

I've been tasked with building an XSD to validate a given xml, my issue is that some of the XML elements are of the form

<ElementName description="i am an element">1234567</ElementName>

I need to build the XSD that validates the Element 'value' not the attribute so with my increadibly limited experience in building XSDs (I've read the W3C tutorial) i tried this

<xs:element name ="ElementName" type="xs:int">
    <xs:complexType mixed="true">
         <xs:attribute name="description" type="xs:string"/>
    </xs:complexType>
</xs:element>

and lo and behold ... it doesn't work, it says:

"The Type attribute cannot be present with either simpleType or complexType"

i'm sure it's some thing stupid i've done but couldn't find an answer/misinterpreted answers elsewhere !

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若言繁花未落 2024-09-17 17:48:24

混合类型是不同的。您需要具有简单内容的复杂类型:

<xs:element name="ElementName">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:int">
        <xs:attribute name="description" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

另请参阅:

Mixed types are something different. You need a complex type with simple content:

<xs:element name="ElementName">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:int">
        <xs:attribute name="description" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文