基礎結構: 我使用JAVA 1.5,這是強制性的。但我可以加載任何外部庫,所以沒問題。使用Java進行XML動態驗證
問題:
我有一個XML文件,通過「外部通道」 recived,我可以用它爲InputStream的
,如果有人需要得到同樣的,可以使用:
InputStream is = new FileInputStream(file);
我需要驗證XSD對XSD的內容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>
所以我有一個XSD文件早午餐。
一大塊XML文件是這樣的
<?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>
,所以我需要驗證對CBISDDReqPhyMsg.00.00.06的XML。所以我只知道在運行時反對偉大的XML使用。例如另一個文件可以加載CBISDDReqPhyMsg.00.00.05
我有兩個主要問題
1)我需要從XML和XML獲得XSD文件名可能是BIG 1/2GB(STAX /薩克斯是一個很好的解決方案)
2)我需要從jar中加載xsd,因爲整個應用程序無法訪問文件系統。
爲了驗證我喜歡像http://www.edankert.com/validate.html
系統我讀到包括在這個答案Problem validating an XML file using Java with an XSD having an include
但是用裝載機我無法獲取有關文件的相關信息。
有些想法?
關於#1:XML文檔本身沒有文件名 - 這又如何涉及到的文件大小? – home
我需要獲得的xsd文件名稱和文件的大小是我不能使用DOM這兩個句子是相關的信息,我無法加載整個文件和稍後搜索文件中的大小。 – user1594895
@ user1594895在XSD文件名和XML中的數據之間是否有模式?我見過許多情況下沒有模式... –