开发者

Represent a List of Objects in XSD

开发者 https://www.devze.com 2023-02-05 20:02 出处:网络
How I can represent a list of objects in XSD, for example, given a XML like this? <msgBody> <Contato>

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>
   <开发者_C百科cdBairro>99797781</nrLinha>
   <email>foo@foo.com</email>
  </Contato>
 </msgBody>

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


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>


Use a sequence as shown below:

<?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 name="Contato" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:int" name="cdEndereco"/>
              <xs:element type="xs:int" name="cdBairro"/>
              <xs:element type="xs:string" name="email"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
0

精彩评论

暂无评论...
验证码 换一张
取 消