views:

156

answers:

1

I have an XSD that I created. A Transaction Header can one or more Transaction-Items. This XSD will only allow ONE Transaction Header and multiple Transaction-Items in an XML file. I am looking for MULTIPLE Transaction Headers with it's related multiple Transaction-Items. What is missing in the XSD to allow me to do this? Thanks.

<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2010 (http://www.altova.com)--&gt;
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xs:element name="transaction-item">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="StartDate"/>
       <xs:element ref="EndDate"/>
       <xs:element ref="Amount"/>
       <xs:element ref="BusinessPartnerID"/>
       <xs:element ref="Description"/>
      </xs:sequence>
      <xs:attribute name="type" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:string">
         <xs:enumeration value="Production or Import"/>
         <xs:enumeration value="Transfer: Release Obligation"/>
         <xs:enumeration value="Transfer: Retain Obligation"/>
         <xs:enumeration value="Acquire: Without Obligation"/>
         <xs:enumeration value="Acquire: With Obligation"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
     </xs:complexType>
    </xs:element>
    <xs:element name="Amount">
     <xs:simpleType>
      <xs:restriction base="xs:positiveInteger"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="Year">
     <xs:simpleType>
      <xs:restriction base="xs:short"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="TransactionHeader">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="Quarter"/>
       <xs:element ref="Year"/>
       <xs:element ref="FuelPathwayCode"/>
       <xs:element ref="PhysicalPathwayCode"/>
      </xs:sequence>
     </xs:complexType>
    </xs:element>
    <xs:element name="StartDate">
     <xs:simpleType>
      <xs:restriction base="xs:date"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="Quarter">
     <xs:simpleType>
      <xs:restriction base="xs:byte"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="PhysicalPathwayCode">
     <xs:simpleType>
      <xs:restriction base="xs:string">
       <xs:enumeration value="PP001"/>
       <xs:enumeration value="PP002"/>
       <xs:enumeration value="PP003"/>
       <xs:enumeration value="PP004"/>
       <xs:enumeration value="PP005"/>
       <xs:enumeration value="PP006"/>
       <xs:enumeration value="PP007"/>
      </xs:restriction>
     </xs:simpleType>
    </xs:element>
    <xs:element name="LCFS-report">
     <xs:complexType>
      <xs:sequence>
       <xs:element ref="TransactionHeader"/>
       <xs:element ref="transaction-item" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="total-sum" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:byte"/>
       </xs:simpleType>
      </xs:attribute>
      <xs:attribute name="detailed" type="xs:boolean" use="required"/>
      <xs:attribute name="currency" use="required">
       <xs:simpleType>
        <xs:restriction base="xs:string">
         <xs:enumeration value="USD"/>
        </xs:restriction>
       </xs:simpleType>
      </xs:attribute>
     </xs:complexType>
    </xs:element>
    <xs:element name="FuelPathwayCode">
     <xs:simpleType>
      <xs:restriction base="xs:string">
       <xs:enumeration value="CARBOB001"/>
       <xs:enumeration value="CARBOB002-HIGH"/>
       <xs:enumeration value="CARBOB002-INC"/>
       <xs:enumeration value="Ethanol001"/>
       <xs:enumeration value="Ethanol002"/>
       <xs:enumeration value="Ethanol003"/>
       <xs:enumeration value="Ethanol004"/>
       <xs:enumeration value="Ethanol005"/>
       <xs:enumeration value="Ethanol006"/>
       <xs:enumeration value="Ethanol007"/>
       <xs:enumeration value="Ethanol008"/>
       <xs:enumeration value="Ethanol009"/>
       <xs:enumeration value="Ethanol0010"/>
       <xs:enumeration value="Ethanol0012"/>
       <xs:enumeration value="Fossil CNG001"/>
       <xs:enumeration value="Fossil CNG002"/>
       <xs:enumeration value="Biogas CNG001"/>
       <xs:enumeration value="Electricity001_30"/>
       <xs:enumeration value="Electricity002_27"/>
       <xs:enumeration value="ULSD-CA Diesel Fuel"/>
       <xs:enumeration value="Compressed Hydrogen001"/>
       <xs:enumeration value="Liquid Hydrogen001"/>
       <xs:enumeration value="Compressed Hydrogen002"/>
       <xs:enumeration value="Compressed Hydrogen003"/>
      </xs:restriction>
     </xs:simpleType>
    </xs:element>
    <xs:element name="EndDate">
     <xs:simpleType>
      <xs:restriction base="xs:date"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="Description">
     <xs:simpleType>
      <xs:restriction base="xs:string"/>
     </xs:simpleType>
    </xs:element>
    <xs:element name="BusinessPartnerID">
     <xs:simpleType>
      <xs:restriction base="xs:short"/>
     </xs:simpleType>
    </xs:element>
</xs:schema>
+2  A: 

First, I would convert your TransactionHeader to a separate type:

    <xs:complexType name="TransactionHeaderType">
            <xs:sequence>
                    <xs:element ref="Quarter"/>
                    <xs:element ref="Year"/>
                    <xs:element ref="FuelPathwayCode"/>
                    <xs:element ref="PhysicalPathwayCode"/>
            </xs:sequence>
    </xs:complexType>

Then you can define a new element of complex type that can contain any number of transaction headers:

  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="TransactionHeader" 
                    type="TransactionHeaderType"  
                    minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

By default, in XML Schema, minOccurs and maxOccurs both are set to 1 - but in a sequence, you can change that number to anything you like - including the "unbounded" for maxOccurs.

Marc

marc_s