XSD Validation, checking for required elements
573589Apr 20 2007 — edited May 13 2008I'm using the FTP Adapter to retrieve a flat file in a format like this -
H|1|1234|5-APR-2007
L|1|33123|2
L|1|12345|1
L|1|6969|5
S|1|Milton Park, Abingdon, OX142NF
I have generated an XSD file using the built in wizard that looks like this -
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
targetNamespace="http://bpelns.corp.rmd.org/complex"
xmlns:tns="http://bpelns.corp.rmd.org/complex"
elementFormDefault="qualified"
attributeFormDefault="unqualified" nxsd:encoding="ASCII" nxsd:stream="chars" nxsd:version="NXSD">
<xsd:element name="order">
<xsd:complexType>
<xsd:choice minOccurs="1" maxOccurs="unbounded" nxsd:choiceCondition="terminated" nxsd:terminatedBy="|">
<xsd:element name="HEADER" minOccurs="1" maxOccurs="1" nillable="false" nxsd:conditionValue="H">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ORDERID" nillable="false" minOccurs="1" maxOccurs="1" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="CUSTOMERID" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="ORDERDATE" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="LINEITEM" minOccurs="1" maxOccurs="unbounded" nxsd:conditionValue="L">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ORDERID" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="PRODUCTCODE" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="QUANTITY" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="SHIPPING" minOccurs="1" maxOccurs="1" nxsd:conditionValue="S">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ORDERID" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="ADDRESS" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
I added the various minOccurs & maxOccurs attributes. I would like to be able to state that the element HEADER is required. However, despite the min & max values it carries straight through to the next point in the BPEL flow. I cannot use the required attribute type, as JDeveloper does not recognise this.
How can I acheive the validation I require ? Is the XSD the right place to be doing it (I thought so, as it is the schema definition) ? If I cannot do this with the XSD how else might I acheive it in a concise way, ie not using a big switch operation to test various elements.