无法设计 xsd 架构 - 因为元素名称可变 [英] Can't design xsd schema - because of a variable element name

查看:19
本文介绍了无法设计 xsd 架构 - 因为元素名称可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是最擅长创建 XSD 架构的,因为这实际上是我的第一个,我想验证一个必须如下所示的 xml:

i'm not the best at creating XSD schema as this is actually my first one, i would like to validate an xml that must look like this :

<?xml version="1.0"?>
<Data>
  <FIELD name='toto'>
    <META mono='false' dynamic='false'>
      <COLUMN1>
          <REFTABLE>table</REFTABLE>
          <REFCOLUMN>key_column</REFCOLUMN>
          <REFLABELCOLUMN>test_column</REFLABELCOLUMN>
      </COLUMN1>
      <COLUMN2>
          <REFTABLE>table</REFTABLE>
          <REFCOLUMN>key_column</REFCOLUMN>
          <REFLABELCOLUMN>test_column</REFLABELCOLUMN>
      </COLUMN2>
</META>
<VALUEs>
   <VALUE>...</VALUE>
</VALUEs>
</FIELD>

我的问题是进入 META 块的标签COLUMN1"、COLUMN2"总是不同的,它可能变成 COLUMNxxx.现在我的架构是:

My problem is that into the META block the tags "COLUMN1","COLUMN2" are always different, it may become COLUMNxxx. For now my schema is :

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Data">
    <xsd:complexType>
   <xsd:sequence>
     <xsd:element name="FIELD" type="Field" />
    </xsd:sequence>
      <xsd:attribute name="id" type="xsd:int" use="required" />
    </xsd:complexType>
</xsd:element>

<xsd:complexType name="dataSourceDef">
    <xsd:sequence>
        <xsd:element name="DSD_REFTABLE" type="xsd:string" />
        <xsd:element name="DSD_REFCOLUMN" type="xsd:string" />
        <xsd:element name="DSD_REFLABELCOLUMN" type="xsd:string" />
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="MetaTag">
    <xsd:sequence>
        <xsd:any processContents="lax" />
    </xsd:sequence>
    <xsd:attribute name="mono" type="xsd:string" use="required" />
    <xsd:attribute name="dynamic" type="xsd:string" use="required"/>
</xsd:complexType>

<xsd:complexType name="Field">
    <xsd:sequence>
        <xsd:element name="META" type="MetaTag" minOccurs="1" />
        <xsd:element name="VALUEs">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:any processContents="lax" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>

我就是无法让它工作,我不知道如何处理我的节点的精确级别不清楚的事实,其余的是.

And i just can't get it to work, i don't know how to handle the fact that a precise level of my nodes isn't clear, and the rest is.

你能帮我吗?

推荐答案

我认为问题在于,在您的架构中, 将只接受一个元素.您需要说明可以有任意数量的具有 minOccursmaxOccurs 属性的孩子:

I think the problem is that, in your schema, <xsd:any/> will only accept one single element. You need to tell that there can be any number of children with the attributes minOccurs and maxOccurs:

<xsd:sequence>
    <xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>

这篇关于无法设计 xsd 架构 - 因为元素名称可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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