XML Parsing & validation against the schema .XSD
Posted: Tue May 17, 2011 2:42 pm
Hi All,
My requriment is to validate the XML based on the XSD schema. Is it possible to impelement in our datastage job.
Sample XSD schema below; The reference element "Activity" is a user defined element "ActivityDataType" and it has list of restricted values as highlighed below. Only any one of the listed value can be the value for the element in the XML file otherwise the validation needs to be failed.
<?xml version ="1.0" encoding = "UTF-8"?>
<xsd:schema targetNamespace="SDR_Body_1-0"
xmlns="SDR_Body_1-0"
xmlns:h="SDR_Header_1-0"
xmlns:fpml="http://www.fpml.org/FpML-5/transparency"
xmlns:fpmlreport="http://www.fpml.org/FpML-5/reporting"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1-0">
<xsd:import namespace="http://www.fpml.org/FpML-5/transparency" schemaLocation="/xmls/SDR/transparency/fpml-main-5-2.xsd" />
<xsd:import namespace="http://www.fpml.org/FpML-5/reporting" schemaLocation="/xmls/SDR/reporting/fpml-main-5-2.xsd" />
<xsd:import namespace="SDR_Header_1-0" schemaLocation="/xmls/SDR/transparency/SDR_Trans_Header_1-0.xsd" />
<!-- Begin Level 1 =============================================-->
<xsd:element name="SDR_Body">
<xsd:complexType mixed="false">
<xsd:sequence>
<xsd:element ref="Activity"/>
<xsd:element ref="Status"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- End Level 1 ===============================================-->
<!-- Begin simple element name type declarations ======================= -->
<xsd:element name="Activity" type="ActivityDataType"/>
<!-- End simple element name type declarations ===================== -->
<!-- Begin custom element datatype declarations ==================== -->
<xsd:simpleType name="ActivityDataType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Cancel"/>
<xsd:enumeration value="Correct"/>
<xsd:enumeration value="LifeCycle"/>
<xsd:enumeration value="New"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
My question is either can we do this kind of schema validation in datastage. If it possible; then how can we implement this.
Thanks,
Dina
My requriment is to validate the XML based on the XSD schema. Is it possible to impelement in our datastage job.
Sample XSD schema below; The reference element "Activity" is a user defined element "ActivityDataType" and it has list of restricted values as highlighed below. Only any one of the listed value can be the value for the element in the XML file otherwise the validation needs to be failed.
<?xml version ="1.0" encoding = "UTF-8"?>
<xsd:schema targetNamespace="SDR_Body_1-0"
xmlns="SDR_Body_1-0"
xmlns:h="SDR_Header_1-0"
xmlns:fpml="http://www.fpml.org/FpML-5/transparency"
xmlns:fpmlreport="http://www.fpml.org/FpML-5/reporting"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1-0">
<xsd:import namespace="http://www.fpml.org/FpML-5/transparency" schemaLocation="/xmls/SDR/transparency/fpml-main-5-2.xsd" />
<xsd:import namespace="http://www.fpml.org/FpML-5/reporting" schemaLocation="/xmls/SDR/reporting/fpml-main-5-2.xsd" />
<xsd:import namespace="SDR_Header_1-0" schemaLocation="/xmls/SDR/transparency/SDR_Trans_Header_1-0.xsd" />
<!-- Begin Level 1 =============================================-->
<xsd:element name="SDR_Body">
<xsd:complexType mixed="false">
<xsd:sequence>
<xsd:element ref="Activity"/>
<xsd:element ref="Status"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- End Level 1 ===============================================-->
<!-- Begin simple element name type declarations ======================= -->
<xsd:element name="Activity" type="ActivityDataType"/>
<!-- End simple element name type declarations ===================== -->
<!-- Begin custom element datatype declarations ==================== -->
<xsd:simpleType name="ActivityDataType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Cancel"/>
<xsd:enumeration value="Correct"/>
<xsd:enumeration value="LifeCycle"/>
<xsd:enumeration value="New"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
My question is either can we do this kind of schema validation in datastage. If it possible; then how can we implement this.
Thanks,
Dina