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

时间:2014-01-03 17:42:31

标签: xsd base64 xop

我有一个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验证程序):

  

元素'mds:xml-schema:soap11:PackageBinary'不能包含child   元素'http://www.w3.org/2004/08/xop/include:Include'因为   父元素的内容模型仅为文本。

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

3 个答案:

答案 0 :(得分:0)

我能想到的最好的方法是创建一个允许任何标签的复杂类型,但也标记为“混合”,因此它允许文本。这并没有明确地将内容声明为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"/>

答案 1 :(得分:0)

我发现的解决方案是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://example.org"
           elementFormDefault="qualified"
           xmlns="http://example.org" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:xop="http://www.w3.org/2004/08/xop/include">

<xs:import namespace="http://www.w3.org/2004/08/xop/include"
           schemaLocation="http://www.w3.org/2004/08/xop/include"/>

<xs:complexType name="PackageBinary" mixed="true">
  <xs:all>
    <xs:element ref="xop:Include"/>
  </xs:all>
</xs:complexType>

答案 2 :(得分:0)

我在xml文档中看到这个似乎允许验证 - 基本上属性xmlns:xop =&#34; ...&#34;做了诀窍:

<SomeElement xmlns:xop="http://www.w3.org/2004/08/xop/include/" id="465390" type="html">
<SomeElementSummaryURL>https://file.someurl.com/SomeImage.html</SomeElementSummaryURL>
<xop:Include href="cid:1111111@someurl.com"/>
</SomeElement >
相关问题