gpt4 book ai didi

xsd - 如何定义允许 base64 内容或 xop :Include element? 的 XML 架构元素

转载 作者:行者123 更新时间:2023-12-05 00:01:01 25 4
gpt4 key购买 nike

我有一个 XML 模式,它定义了一个元素,该元素可以是 base64 文本或 xop:Include 元素。目前,这被定义为 base64Binary 类型:

<xs:element name="PackageBinary" type="xs:base64Binary" minOccurs="1" maxOccurs="1"/>

当我插入 xop:Include 元素时,它看起来像这样:
<PackageBinary>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="http://google.com/data.bin" />
</PackageBinary>

但这会导致 XML 验证错误(我使用的是 .NET 验证器):

The element 'mds:xml-schema:soap11:PackageBinary' cannot contain child element 'http://www.w3.org/2004/08/xop/include:Include' because the parent element's content model is text only.



这是有道理的,因为它不是 base64 内容,但我认为这是常见的做法......?有没有办法在模式中支持这一点? (我们有支持这种语法的现有产品,但我们现在正在添加验证。)

最佳答案

我能想到的最好方法是创建一个复杂类型,它允许任何标签,但也被标记为“混合”,因此它允许文本。这并没有明确地将内容声明为 base64,但它确实让它通过了验证。

<xs:complexType name="PackageBinaryInner" mixed="true">
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PackageBinary" type="PackageBinaryInner" minOccurs="1" maxOccurs="1"/>

关于xsd - 如何定义允许 base64 内容或 xop :Include element? 的 XML 架构元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20909580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com