Infrastructure: I'm using JAVA 1.5 and this is mandatory. But i can load any external lib so no problem.
Problem:
I have an XML file recived via "an external channel" and I can use it as InputStream
if someone need to get the same, could use:
InputStream is = new FileInputStream(file);
I need to validate the XML against XSD that has neasted XSD
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:BODY="urn:CBI:xsd:CBIBdySDDReq.00.00.06"
xmlns:HTRT="urn:CBI:xsd:CBIHdrTrt.001.07"
xmlns:HE2E="urn:CBI:xsd:CBIHdrSrv.001.07"
xmlns:SGNT="urn:CBI:xsd:CBISgnInf.001.04"
xmlns:LMSG="urn:CBI:xsd:CBISDDReqLogMsg.00.00.06"
xmlns="urn:CBI:xsd:CBISDDReqPhyMsg.00.00.06"
targetNamespace="urn:CBI:xsd:CBISDDReqPhyMsg.00.00.06"
elementFormDefault="qualified">
<xs:import namespace="urn:CBI:xsd:CBIHdrTrt.001.07" schemaLocation="CBIHdrTrt.001.07.xsd"/>
<xs:import namespace="urn:CBI:xsd:CBIHdrSrv.001.07" schemaLocation="CBIHdrSrv.001.07.xsd"/>
<xs:import namespace="urn:CBI:xsd:CBIBdySDDReq.00.00.06" schemaLocation="CBIBdySDDReq.00.00.06.xsd"/>
<xs:element name="CBISDDReqPhyMsg" type="CBISDDReqPhyMsg.00.00.06">
<xs:annotation>
<xs:documentation>1. - Tag root dell'intero messaggio fisico di richiesta SDD CBI</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="CBISDDReqPhyMsg.00.00.06">
<xs:sequence>
<xs:element name="CBIHdrTrt" type="HTRT:CBIHdrTrt.001.07">
<xs:annotation>
<xs:documentation>1.1. - Header di tratta CBI</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CBIHdrSrv" type="HE2E:CBIHdrSrv.001.07">
<xs:annotation>
<xs:documentation>1.2. - Header di servizio CBI</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="CBIBdySDDReq" type="BODY:CBIBdySDDReq.00.00.06">
<xs:annotation>
<xs:documentation>1.3. - Body di servizio CBI</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
So I have a brunch of XSD file.
A chunk XML file is this
<?xml version="1.0" encoding="UTF-8"?>
<MSG:CBISDDReqPhyMsg xmlns:MSG="urn:CBI:xsd:CBISDDReqPhyMsg.00.00.06"
xmlns:HTRT="urn:CBI:xsd:CBIHdrTrt.001.07" xmlns:HE2E="urn:CBI:xsd:CBIHdrSrv.001.07"
xmlns:BODY="urn:CBI:xsd:CBIBdySDDReq.00.00.06" xmlns:LMSG="urn:CBI:xsd:CBISDDReqLogMsg.00.00.06"
xmlns:SGNT="urn:CBI:xsd:CBISgnInf.001.04" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MSG:CBIHdrTrt>
<HTRT:IdCBISndrf>0000636J</HTRT:IdCBISndrf>
<HTRT:IdCBIRcvrf>0000641V</HTRT:IdCBIRcvrf>
<HTRT:SrvNm>INC-SDDC</HTRT:SrvNm>
<HTRT:IdMsgTrt>
0000636JP12312111154007381042010010000636J000000636J0000641V0
</HTRT:IdMsgTrt>
So i need to validate the XML against CBISDDReqPhyMsg.00.00.06. So i know only at runtime against wich xml to use. Example another file could load CBISDDReqPhyMsg.00.00.05
I have two major problem
1) I need to obtain the xsd file name from XML and XML could be BIG 1/2GB (stax/sax are a nice solution)
2) I need to load the xsd from a jar because the whole app cannot have access to the file system.
For validation i prefer a system like http://www.edankert.com/validate.html
I read about include in this answer Problem validating an XML file using Java with an XSD having an include
But using the loader i can't obtain the infos about file.
Some idea?