XML Schema强制执行子元素而不强制执行标记名称

时间:2021-11-02 20:21:29

I trying to make a schema for the following xml.

我试图为以下xml创建一个模式。

<root>
    <allow_any_name id="string">
        <required_tag_1>string</required_tag_1>
        <required_tag_2>string</required_tag_2>
        <required_tag_3>string</required_tag_3>
    </allow_any_name>

    <name1 id="string">
        <required_tag_1>string</required_tag_1>
        <required_tag_2>string</required_tag_2>
        <required_tag_3>string</required_tag_3>
    </name1>

    <name2 id="string">
        <required_tag_1>string</required_tag_1>
        <required_tag_2>string</required_tag_2>
        <required_tag_3>string</required_tag_3>
    </name2>

</root>

The main problem is that I can't find a way to specify the child elements with any specifying the tag name as well. In the above xml the allow_any_name tag could be any name.

主要问题是我找不到指定子元素的方法,也指定了标记名称。在上面的xml中,allow_any_name标记可以是任何名称。

I have tried <xs:any processContents="lax"></xs:any> which allow any tag name but does not allow me to specify the children.

我尝试过 ,它允许任何标记名称,但不允许我指定子项。 :any>

I also tried using <xs:any processContents="strict" namespace="##local"></xs:any> which enforces the child elements but means I have to know all the tag names used (which I don't)

我也尝试使用 强制执行子元素,但意味着我必须知道所有使用的标记名称(我不知道) :any>

Thanks

谢谢

2 个解决方案

#1


1  

It's not possible with XSD 1.0.

XSD 1.0无法实现。

In XSD 1.1 it can be done using assertions.

在XSD 1.1中,可以使用断言完成。

#2


0  

I think this is not possible with XML Schema. I think you must change your structure from

我认为这不适用于XML Schema。我认为你必须改变你的结构

<allow_any_name id="string">
  <required_tag_1>string</required_tag_1>
  <required_tag_2>string</required_tag_2>
  <required_tag_3>string</required_tag_3>
</allow_any_name>

to something like this:

这样的事情:

<fixed_tag_name id="string" name="allow_any_name">
  <required_tag_1>string</required_tag_1>
  <required_tag_2>string</required_tag_2>
  <required_tag_3>string</required_tag_3>
</fixed_tag_name>

hth

心连心

#1


1  

It's not possible with XSD 1.0.

XSD 1.0无法实现。

In XSD 1.1 it can be done using assertions.

在XSD 1.1中,可以使用断言完成。

#2


0  

I think this is not possible with XML Schema. I think you must change your structure from

我认为这不适用于XML Schema。我认为你必须改变你的结构

<allow_any_name id="string">
  <required_tag_1>string</required_tag_1>
  <required_tag_2>string</required_tag_2>
  <required_tag_3>string</required_tag_3>
</allow_any_name>

to something like this:

这样的事情:

<fixed_tag_name id="string" name="allow_any_name">
  <required_tag_1>string</required_tag_1>
  <required_tag_2>string</required_tag_2>
  <required_tag_3>string</required_tag_3>
</fixed_tag_name>

hth

心连心