XSD One to Many Schema

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi,
I am new to XML schemas.
I am going to be moving a text file from machine A to machine B. (My app on
both)
So I figured I would construct an XSD schema of the file layout (which in
itself is a rolling around in my head.)
Anyway I see this file having a one contains many structure.
ie There is a Batch element which will contain a number of BatchMember
Elements.
I can see how to construct this in the XML editor.
I want
<FileList xmlns="http://tempuri.org/MyFile.xsd>
<Header> some header stuff <\Header>
<Batch>
<BatchNum>1</BatchNum>
<BatchMember>1</BatchMember>
<BatchMember>2</BatchMember>
</Batch>
<Batch>
<BatchNum>2</BatchNum>
<BatchMember>1</BatchMember>
<BatchMember>2</BatchMember>
</Batch>
</FileList

The closest I have come is treating Batch and BatchMember like a couple of
database tables with a parent child relationship. But this entails adding a
foreign key field to the BatchMember Element.
This approach also falls short because I want to put multiple batches in the
file.
Is there way to tackle this?
Thanks
Bob
 
Maybe something like so. Note that the BatchNum might be redundant, since
you can rely on XML order.

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="MyFile.xsd"
targetNamespace="http://tempuri.org/MyFile.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/MyFile.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="FileList" type="FileListType" />

<xs:complexType name="FileListType">
<xs:sequence>
<xs:element name="Header" type="xs:string" />
<xs:element name="Batch" type="BatchType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="BatchType">
<xs:sequence>
<xs:element name="BatchNum" type="xs:int" />
<xs:element name="BatcmMember" type="xs:string" maxOccurs="unbounded"
/>
</xs:sequence>
</xs:complexType>

</xs:schema>
 
Back
Top