定义具有相同属性和元素名称的 XSD [英] Defining an XSD with same attribute and element name

查看:36
本文介绍了定义具有相同属性和元素名称的 XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题我已经问过了.我想我之前可能问错了这个问题.我希望具有相同类型的 xsd 元素在 xsd 中出现三次.我想知道是否有可能.

I have already asked this question. I think i might have asked this question wrong previously. I want an xsd element with same type to appear three times in the xsd. I want to know if it is possible.

我在下面给出了我预期的 xml 输出.

I have given below my expected xml output.

 <Primary>
     <Name>Harold</Name> (guy1 data)
      <Mobile>2356</Mobile>
  </Primary>
  <Primary>
       <Name>Finch</Name>(guy2 data)
    <Mobile>4567</Mobile>
   </Primary>
   <Primary>
     <Name>John</Name>(guy3 data)
       <Mobile>1234</Mobile>
    </Primary>

我已经为这个预期的 xml 创建了 XSD.

I have created XSD for this intended xml.

<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

这是我想要的场景.我知道主标签将在我的 xml 中出现 3 次.我想知道是否可以使元素在 xsd 中也出现三次.也许是这样的

Here is the scenario I want. I know the primary tag will appear exactly three times in my xml. I was wondering if I could make the elements also appear three times in the xsd. Maybe something like this

<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="primary" minOccurs="0" maxOccurs="unbounded">
<xs:complexType >
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
<xs:element name="mobile" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

如果这是一个愚蠢的问题,我提前道歉.我对 XSD 和 XML 很陌生.我需要它在 xsd 中出现三次的原因是我正在 Visual Studio 2012 中从 Tf xml 生成器创建 xml.我需要在 xsd 中将数据一对一映射.如果我使用复杂类型和序列,它只会在 xsd 中出现一次,并且我无法将 Guy 2 和 Guy 3 的数据与标签相关联,因为它只在 xsd 中出现一次.我正在尝试这样做,因为我试图避免编码.如果我做不到,我会考虑使用visual studio ssis包中的脚本组件.

I apologize in advance if it is a silly question. I am very new to XSD and XML. The reason I need it to appear three times in the xsd is I am creating the xml from Tf xml generator in Visual studio 2012. And I need to map the data one to one in the xsd. If I use the complex type and sequence, it appears only once in the xsd and I can’t relate the data of guy 2 and guy 3 to the tags as it appears only once in the xsd. I am trying to do this as I am trying to avoid coding. If I this can’t be done, I will look into use the script component in visual studio ssis package.

推荐答案

终于经过一个月的搜索和研究,我今天找到了答案.

Finally after a month of searching and researching i found the answer today.

如何为无序列表的 XML 节点创建模式,并有出现约束

使用 XSD 验证 XML ...但仍允许可扩展性

多亏了这两篇文章,我才能够创建一个 xsd,使用 xs:choice 标签使标签在我的 xsd 中出现三次

Thanks to these two posts i was able to create an xsd which will make the tags appear thrice in my xsd with the use of xs:choice tag

这篇关于定义具有相同属性和元素名称的 XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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