来自可变数量的 XML 元素的 XSD [英] XSD from variable number of XML elements

查看:25
本文介绍了来自可变数量的 XML 元素的 XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据我的应用程序中的某些条件创建一个 xml 文档.我的 xml 中的元素数量始终是可变的.例如,有一次它可能看起来像:

I'm creating a xml document based on some conditions in my app. the number of elements inside my xml is always variable. For instance, one time it may look like:

<TransactionTypes>
  <X value="false" text="" />
  <O value="false" text="" />
  <E value="false" text="" />
  <P value="false" text="" />
  <C value="false" text="" />
  <K value="false" text="" />
</TransactionTypes>

还有其他时候:

 <TransactionTypes>
  <TT value="false" text="" />
  <EP value="false" text="" />
  <PY value="false" text="" />
</TransactionTypes>

所以TransactionTypes里面的子元素在元素的名称上总是不同的,但它们总是有value和text属性.我如何为此制作 XSD?

So the child elements inside of TransactionTypes always vary in terms of the name of the elements, but they always have the value and text attributes. How can i make a XSD for this?

推荐答案

我认为您不能在通配符上建立 XSD 限制,然后仍然指定通配符元素的属性.

I don't think you can build a XSD restriction on a wildcard and then still specify the attributes of the wild-card element.

唯一可能的标签可能是any":http://www.w3schools.com/schema/schema_complex_any.asp

The only possible tag might be "any": http://www.w3schools.com/schema/schema_complex_any.asp

无法定义any"可能具有的属性.我认为没有其他解决方案.正如你所说的可以有任何类型的元素"......如果您可以定义作为TransactionTypes"子代的所有可能元素,您肯定会做得更好.不管有多少.您可以将所有这些子元素映射到相同的 complexType 并定义属性值/文本,然后只定义一次.但是通配符不起作用.

And what attributes "any" may have cannot be defined. I don't think that there is another solution. As you did say "there can be any kind of element" ... You would definitely do better if you could define all possible elements that are child of "TransactionTypes". No matter how many there are. You could map all those child element to the same complexType and define the attributes value/text then only one time still. However wildcard will not work.

塞巴斯蒂安

这篇关于来自可变数量的 XML 元素的 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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