How to read multiple rows of file using XSD that is inside a <sequence>? the xsd reads only the first record - xsd

Below is source file:
SOURCE FILE
The rows that start with 5 are RecordType5 and rows starting with 6 and 7 belong to RecordType5. In sense that rows starting with 6 and 7 are children of row starting with 5.
Again each row is a fixedlength row where some lengths identify each field. Now I want to read all the 6 type rows and 7 type rows under the main 5 type row.
My problem is my XSD just reads the first occurrence of the 6 and 7 type row and ignores rest. I have added the maxOccurs:unbounded and still it doesn't read it.
I have separate complex types for 6 and 7 type records. My guess is since it is inside <sequence> it just reads the first occurrence and ignores rest. But I do not know how to make it read all records. I need to use sequence because the 5 type row needs to be read in fixedlength style.
Below is the XSD:
`<xsd:element name="PaymentAckData">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PaymentAck" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="tns:RecordType1" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="1" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
<xsd:element ref="tns:RecordType5" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="5" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
<xsd:element ref="tns:RecordType8" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="8" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
<xsd:element ref="tns:RecordType9" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="9" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType1 -->
<xsd:element name="RecordType1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="AdditionalData" type="xsd:string" nxsd:length="93" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:terminatedBy="${eol}" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType5 -->
<xsd:element name="RecordType5">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="ServiceClassCode" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="3"/>
<xsd:element name="CompanyName" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="16"/>
<xsd:element name="CompanyDiscretionaryData" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="20"/>
<xsd:element name="CompanyIdentification" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="10"/>
<xsd:element name="StandardEntryClassCode" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="3"/>
<xsd:element name="CompanyEntryDescription" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="10"/>
<xsd:element name="CompanyDiscriptiveDate" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="6"/>
<xsd:element name="EffectiveEntryDate" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="6"/>
<xsd:element name="SettlementDate" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="3"/>
<xsd:element name="OriginatorStatusCode" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="1"/>
<xsd:element name="OriginatingDFIIdentification" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="8"/>
<xsd:element name="BatchNumber" type="xsd:string" nxsd:length="7" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:terminatedBy="${eol}" />
<xsd:element ref="tns:RecordType6" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="6" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
<xsd:element ref="tns:RecordType7" minOccurs="0" maxOccurs="unbounded" nxsd:startsWith="7" nxsd:lookAhead="0" nxsd:lookTill="${eol}"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType6 -->
<xsd:element name="RecordType6">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="TransactionCode" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="2"/>
<xsd:element name="ReceivingDFIIdentification" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="8"/>
<xsd:element name="CheckDigit" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="1"/>
<xsd:element name="DFIAccountNumber" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="17"/>
<xsd:element name="Amount" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="10"/>
<xsd:element name="IdentificationNumber" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="15"/>
<xsd:element name="ReceivingCompany" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="22"/>
<xsd:element name="DescretionaryData" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="2"/>
<xsd:element name="AddendaRecordIndicator" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="1"/>
<xsd:element name="TraceNumber" type="xsd:string" nxsd:length="15" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:terminatedBy="${eol}" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType7 -->
<xsd:element name="RecordType7">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="AddendaTypeCode" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="2"/>
<xsd:element name="PaymentRelatedInformation" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="80"/>
<xsd:element name="AddendaSequenceNumber" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="4"/>
<xsd:element name="EntryDetailSeqNumber" type="xsd:string" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="7" nxsd:terminatedBy="${eol}" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType8 -->
<xsd:element name="RecordType8">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="AdditionalData" type="xsd:string" nxsd:length="93" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:terminatedBy="${eol}" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- RecordType9 -->
<xsd:element name="RecordType9">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RecordType" type="xsd:string" nxsd:style="fixedLength" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:length="0"/>
<xsd:element name="AdditionalData" type="xsd:string" nxsd:length="93" nxsd:style="terminated" nxsd:minOccurs="0" nxsd:maxOccurs="1" nxsd:nillable="true" nxsd:terminatedBy="${eol}" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>`
I tried using tag instead of sequence but apparently it needs <startsWith> or <lookAhead> with <lookFor>. But I cannot use startwith and all for fixedlength style anyways. Errors out when trying to use <Sequence> for fixedlength and <choice> for 6 and 7 type rows saying unexpected element choice.

Related

<choice> not support when writing xsd schema for EMF

I am writing a schema for EMF to describe general graphs. The problem is that if this is directed graph, then the edge should have properties of src_node and dst_node, otherwise it has node_one and node_two. I tried to use "choice" to have mutally exclusive elements but in EMF it functions the same as "sequence". e.g a similar problem for NodeProperty
<xsd:complexType name="NodeProperty">
<xsd:choice>
<xsd:element name="StringValue" type="xsd:string"/>
<xsd:element name="IntValue" type="xsd:int"/>
<xsd:element name="DoubleValue" type="xsd:double"/>
</xsd:choice>
<xsd:attribute name="Property" type="xsd:string"/>
</xsd:complexType>
Another problem in substitutionGroup is that src_node and dst_node are claimed be to unresolved by EMF. The complete code:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:simpleType name="GraphType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Directed"/>
<xsd:enumeration value="Undirected"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="NodeProperty">
<xsd:choice>
<xsd:element name="StringValue" type="xsd:string"/>
<xsd:element name="IntValue" type="xsd:int"/>
<xsd:element name="DoubleValue" type="xsd:double"/>
</xsd:choice>
<xsd:attribute name="Property" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="Node">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="Node" type="lib:NodeProperty"/>
</xsd:sequence>
<xsd:attribute name="NodeName" type="xsd:string" />
</xsd:complexType>
<xsd:element name="src_node" type="xsd:anyURI" ecore:reference="lib:Node"/>
<xsd:element name="node_one" type="xsd:anyURI" substitutionGroup="src_node"/>
<xsd:element name="dst_node" type="xsd:anyURI" ecore:reference="lib:Node"/>
<xsd:element name="node_two" type="xsd:anyURI" substitutionGroup="dst_node"/>
<xsd:complexType name="Edge">
<xsd:sequence>
<xsd:element ref="src_node"/>
<xsd:element ref="dst_node"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="GeneralGraph">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="type" type="lib:GraphType"/>
<xsd:element name="NodeList">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="Node" type="lib:Node"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="EdgeList">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="Edge" type="lib:Edge"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Yes. Substitution groups apply to global elements. So move your elements out of your type and reference to them in the type.
<xsd:element name="src_node" type="xsd:anyURI" ecore:reference="lib:Node"/>
<xsd:element name="node_one" type="xsd:anyURI" substitutionGroup="src_node"/>
<xsd:element name="dst_node" type="xsd:anyURI" ecore:reference="lib:Node"/>
<xsd:element name="node_two" type="xsd:anyURI" substitutionGroup="dst_node"/>
<xsd:complexType name="Edge">
<xsd:sequence>
<xsd:element ref="src_node"/>
<xsd:element ref="dst_node"/>
</xsd:sequence>
</xsd:complexType>
Untested.
The idea is that now node_one could be used instead src_node in Edge and node_two instead of node_two.
Note that type of the substitutable must be derived from the type of the substitution group element. So I used anyURI just for example. You'll probably want to rework it.
By the way I generally discourage usage of subsitition groups. Makes your XML unpredictable.

Create excel file from complex xml-schema

I'm looking at the feasibility of using an Excel file for loading data into the EPA GHG schema (ghg_subpartp_inputs_v1.0.xsd) for defining the XML Subpartp Inputs data.
I'm not well versed or practiced in using Excel and xml-schemas.
The SubpartP schema has nested complex elements, and it won't be accepted into Excel via the XML Maps facility.
Error message: "Cannot Load the specified XML or schema source."
I'm thinking it is because it is a partial schema that is meant to be included in others?
Here is the schema itself:
Schema Name : ghg_subpartp_inputs_v1.0.xsd
Description : Inputs Verifier Tool - XML schema for Subpart P inputs
<xsd:complexType name="SubpartPInputsType">
<xsd:sequence>
<xsd:element name="SubpartPUnitInputs" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="UnitName" type="xsd:string"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EquationP1FeedstockInputs" type="EquationP1FeedstockInputsType" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="EquationP2FeedstockInputs" type="EquationP2FeedstockInputsType" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="EquationP3FeedstockInputs" type="EquationP3FeedstockInputsType" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="UniqueSubpartPFeedstockName">
<xsd:selector xpath="Values/*"/>
<xsd:field xpath="FeedstockName"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EquationP1FeedstockInputsType">
<xsd:sequence>
<xsd:element name="FeedstockName" type="xsd:string"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MassOrVolume" type="MassOrVolumeIndicatorType"/>
<xsd:element name="EquationP1MonthlyInputs" minOccurs="0" maxOccurs="12">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MonthName" type="MonthNameList"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Mass" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg of fuel or feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="Volume" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: scf (at standard conditions of 68 degrees F and atmospheric pressure) of fuel or feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="CarbonContent" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg C per kg of fuel or feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="MolecularWeight" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg/kg-mole</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="UniqueEquationP1MonthName">
<xsd:selector xpath="*"/>
<xsd:field xpath="MonthName"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EquationP2FeedstockInputsType">
<xsd:sequence>
<xsd:element name="FeedstockName" type="xsd:string"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MassOrVolume" type="MassOrVolumeIndicatorType"/>
<xsd:element name="EquationP2MonthlyInputs" minOccurs="0" maxOccurs="12">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MonthName" type="MonthNameList"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Mass" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg of fuel or feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="Volume" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: gallons of fuel or feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="CarbonContent" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg C per kg of fuel or feedstock if measured as mass, or kg C per gallon of fuel or feedstock if measured as volume</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="UniqueEquationP2MonthName">
<xsd:selector xpath="*"/>
<xsd:field xpath="MonthName"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="EquationP3FeedstockInputsType">
<xsd:sequence>
<xsd:element name="FeedstockName" type="xsd:string"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="EquationP3MonthlyInputs" minOccurs="0" maxOccurs="12">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MonthName" type="MonthNameList"/>
<xsd:element name="Values">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Mass" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg of fuel and feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="CarbonContent" type="xsd:decimal" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Required units of measure for this equation input: kg C per kg of fuel and feedstock</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:unique name="UniqueEquationP3MonthName">
<xsd:selector xpath="*"/>
<xsd:field xpath="MonthName"/>
</xsd:unique>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
What should I be doing to create the Excel file that will create an acceptible XML for this schema?

How do you map a abstract XSD element in Xquery?

I have a form that I am defining in my Xquery request. This form is built on an XSD schema.
My form:
<xsd:element name="AddInsuranceToOrderForm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="DistributionChannel" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="FloatNumber" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="UserId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="SalesId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="TotalDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ChangeDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
**<xsd:element ref="tns:tenderItem" minOccurs="0" maxOccurs="unbounded"/>**
<xsd:element name="ProtectionPlans" type="tns:ProtectionPlanItemType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="InsurancePlans" type="tns:FeatureItemType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Notice tenderItems is a ref. It's source is here:
<xsd:element abstract="true" name="tenderItem" type="tns:TenderType"/>
<xsd:complexType name="TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="date" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0" name="lineNumber" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="returnTenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderType" type="tns:TenderTypeType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="amount" type="xsd:decimal"/>
<xsd:element maxOccurs="1" minOccurs="0" name="signature" type="tns:SignatureType"/>
</xsd:sequence>
</xsd:complexType>
There are several specific tenders that extend tenderType that I want to add to my Xquery request. Here is an example:
<xsd:element name="billToAccount" substitutionGroup="tns:tenderItem" type="tns:BillToAccountType"/>
<xsd:complexType name="BillToAccountType">
<xsd:complexContent>
<xsd:extension base="tns:TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="accountId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="subscriptionId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="chargeDescription" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="lineItems" type="tns:BillToAccountLineItemType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
So how is this done in Xquery? I've tried the following:
{
for $BillToAccount in $addInsuranceToOrderABM1/ns3:MessagePayload/ns3:AddInsuranceToOrder/ns1:AddInsuranceToOrderDataArea/ns2:TenderItem
return
<ns2:billToAccount>
{
for $Date in $BillToAccount/ns0:Date
return
<ns2:date>{ data($Date) }</ns2:date>
}…
}
I did this for each tenderType, but the XML elements are not supported by the mapper.
You can use schema-element(ns3:tenderItem) to match any element in that substitution-group.
import schema default element namespace "http://www.example.com/xml-namespace/" at "schema.xsd";
declare variable $input as schema-element(AddInsuranceToOrderForm)
:= validate { doc('data.xml')/AddInsuranceToOrderForm };
for $item in $input/schema-element(tenderItem)
return $item
With schema.xsd as:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:tns="http://www.example.com/xml-namespace/"
targetNamespace="http://www.example.com/xml-namespace/">
<xsd:element name="AddInsuranceToOrderForm">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="OrderId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="DistributionChannel" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="FloatNumber" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="UserId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="SalesId" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<xsd:element name="TotalDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element name="ChangeDue" type="xsd:decimal" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="tns:tenderItem" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element abstract="true" name="tenderItem" type="tns:TenderType"/>
<xsd:complexType name="TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="date" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0" name="lineNumber" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="tenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="returnTenderId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="amount" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="BillToAccount" substitutionGroup="tns:tenderItem" type="tns:BillToAccountType"/>
<xsd:complexType name="BillToAccountType">
<xsd:complexContent>
<xsd:extension base="tns:TenderType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="accountId" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="subscriptionId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="chargeDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
And data.xml as:
<?xml version="1.0" encoding="UTF-8"?>
<AddInsuranceToOrderForm xmlns="http://www.example.com/xml-namespace/">
<OrderId>1</OrderId>
<DistributionChannel>1</DistributionChannel>
<FloatNumber>1</FloatNumber>
<UserId>1</UserId>
<SalesId>1</SalesId>
<TotalDue>1</TotalDue>
<ChangeDue>1</ChangeDue>
<BillToAccount>
<date>2012-10-01T23:59:59</date>
<lineNumber>line 1</lineNumber>
<tenderId>1</tenderId>
<returnTenderId>1</returnTenderId>
<amount>1.2</amount>
<accountId>1</accountId>
<subscriptionId>1</subscriptionId>
<chargeDescription>1</chargeDescription>
</BillToAccount>
</AddInsuranceToOrderForm>
Gives output:
<?xml version="1.0" encoding="UTF-8"?>
<BillToAccount xmlns="http://www.example.com/xml-namespace/">
<date>2012-10-01T23:59:59</date>
<lineNumber>line 1</lineNumber>
<tenderId>1</tenderId>
<returnTenderId>1</returnTenderId>
<amount>1.2</amount>
<accountId>1</accountId>
<subscriptionId>1</subscriptionId>
<chargeDescription>1</chargeDescription>
</BillToAccount>

Any order + constraints for each element

I am trying to create an XSD, which allows child elements to be in any order. But each child element has its own minOccurs and maxOccurs.
My XSD:
<xsd:complexType name="Samples">
<xsd:sequence >
<xsd:element name="Sample1" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:boolean" />
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="Sample2" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string" />
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
For Example a valid XML:
<Samples>
<Sample2></Sample2>
<Sample1></Sample1>
<Sample2></Sample2>
</Samples>
For Example a not valid XML (Sample1 can be choose only one time):
<Samples>
<Sample2></Sample2>
<Sample1></Sample1>
<Sample2></Sample2>
<Sample1></Sample1>
</Samples>
But i don't know, how i can mix the order, while all elements have its own constraint.
Thanks for help
What if you try this:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Samples">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="Sample1" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Of course, you should add your restrictions to each element:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Sample1Type">
<xsd:simpleContent>
<xsd:extension base="xsd:boolean" />
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="Sample2Type">
<xsd:simpleContent>
<xsd:extension base="xsd:string" />
</xsd:simpleContent>
</xsd:complexType>
<xsd:element name="Samples">
<xsd:complexType>
<xsd:sequence>
<xsd:element type="Sample2Type" name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element type="Sample1Type" name="Sample1" minOccurs="1" maxOccurs="1"/>
<xsd:element type="Sample2Type" name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
OR even shorter for simple types:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Samples">
<xsd:complexType>
<xsd:sequence>
<xsd:element type="xsd:string" name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element type="xsd:boolean" name="Sample1" minOccurs="1" maxOccurs="1"/>
<xsd:element type="xsd:string" name="Sample2" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
P.S.::
There are unfortunately no XSD elements like xsd:sequence, which will allow, what you ask.
What you want looks like xsd:all; however, since xsd:all only works for elements for which maxOccurs is 1, it will not work here. If you can combine choices and sequences to constrain your content, one way to go around duplication of definition (avoid defining twice) is to define Sample1 and Sample 2 as global elements and then ref them under your compositors. If defining global elements is not an option except for your root elements, then you could at least define the types globally - this way you maximize the reuse, and somewhat getting closer to your requirement "without defining twice"...

XSD Make minOccurs depend on containing type

I have a complex type defined which doesn't currently contain any minOccurs restrictions. When I use this comlpex type as an element type I sometimes want the elements to have minOccurs 0, other times 1. E.g.
<xsd:complexType name="Identifier">
<xsd:sequence>
<xsd:element name="Id" type="xsd:string"/>
<xsd:element name="Version" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Wibble">
<xsd:sequence>
<xsd:element name="Id" type="Identifier"/> <!-- I want all elements of Identifier to be mandatory when used as part of a 'Wibble' -->
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Wobble">
<xsd:sequence>
<xsd:element name="Id" type="Identifier"/> <!-- I want all elements of Identifier to be optional when used as part of a 'Wobble' -->
</xsd:sequence>
</xsd:complexType>
Is this possible?
Thanks in advance.
Groups are your friend, e.g.
<xsd:group name="IdentifierGroup">
<xsd:sequence>
<xsd:element name="Id" type="Identifier"/>
</xsd:sequence>
</xsd:group>
<xsd:complexType name="Wibble">
<xsd:sequence>
<xsd:group ref="IdentifierGroup" minOccurs="1"/>
<!-- more elements for Wibble here -->
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Wobble">
<xsd:sequence>
<xsd:group ref="IdentifierGroup" minOccurs="0"/>
<!-- more elements for Wobble here -->
</xsd:sequence>
</xsd:complexType>

Resources