在 XSD 中表示对象列表 [英] Represent a List of Objects in XSD

查看:29
本文介绍了在 XSD 中表示对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在 XSD 中表示对象列表,例如,给定这样的 XML?

How I can represent a list of objects in XSD, for example, given a XML like this?

 <msgBody>
  <Contato>
   <cdEndereco>11</cdAreaRegistro>
   <cdBairro>99797781</nrLinha>
   <email>foo@foo.com</email>
  </Contato>
  <Contato>
   <cdEndereco>11</cdAreaRegistro>
   <cdBairro>99797781</nrLinha>
   <email>foo@foo.com</email>
  </Contato>
 </msgBody>

如何将其合并到对象类型 Contato 的列表中?

How I can merge it into a list of object type Contato?

推荐答案

我可能会建议以下架构(即使您的 XML 在粘贴时已损坏):

I may suggest the following schema (even though your XML is broken as pasted):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="msgBody">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="Contato"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Contato">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="cdEndereco"/>
        <xs:element ref="cdBairro"/>
        <xs:element ref="email"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="cdEndereco" type="xs:integer"/>
  <xs:element name="cdBairro" type="xs:integer"/>
  <xs:element name="email" type="xs:string"/>
</xs:schema>

这篇关于在 XSD 中表示对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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