我們試圖將基於位置的FLAT文件(http://i.stack.imgur.com/EryDU.jpg)轉換爲有效的XML。該文件包含標題,明細行,預告片。NULL出現在FLAT文件中,無法使用XSD解析
細節行有數據字符,whilespace字符和其他一些特殊字符,如NULL。
填充一個位置長度的NULL字符。空間也填充一個位置的長度。
我們使用以下XSD解析此平面文件
<?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"
xmlns:tns="http://xmlns.oracle.com/pcbpel/nxsdABO"
targetNamespace="http://xmlns.oracle.com/pcbpel/nxsdABO"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
nxsd:version="NXSD"
nxsd:stream="chars"
nxsd:encoding="ISO-8859-1"
>
<xsd:element name="ROOT">
<xsd:complexType>
<xsd:sequence minOccurs="1">
<xsd:element name="Header" nxsd:startsWith="H" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="InterfaceID" type="xsd:string" nxsd:style="fixedLength" nxsd:length="3" />
<xsd:element name="FileSeqNo" type="xsd:int" nxsd:style="fixedLength" nxsd:length="5" />
<xsd:element name="TimeStamp" type="xsd:int" nxsd:style="fixedLength" nxsd:length="14" />
<xsd:element name="FromSystem" type="xsd:string" nxsd:style="fixedLength" nxsd:length="10" />
<xsd:element name="ToSystem" type="xsd:string" nxsd:style="fixedLength" nxsd:length="10" minOccurs="0"/>
<xsd:element name="FromSAPSys" type="xsd:string" nxsd:style="fixedLength" nxsd:length="8" minOccurs="0"/>
<xsd:element name="FromSAPclt" type="xsd:string" nxsd:style="fixedLength" nxsd:length="3" minOccurs="0"/>
<xsd:element name="ToSAPSys" type="xsd:string" nxsd:style="fixedLength" nxsd:length="8" minOccurs="0"/>
<xsd:element name="ToSAPclt" type="xsd:string" nxsd:style="fixedLength" nxsd:length="4" minOccurs="0"/>
<xsd:element name="UserID" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="DataLine2" nxsd:startsWith="D012" maxOccurs="unbounded" minOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="TransactionType" type="xsd:string" nxsd:style="fixedLength" nxsd:length="2" minOccurs="0"/>
<xsd:element name="Name" type="xsd:string" nxsd:style="fixedLength" nxsd:length="30" />
<xsd:element name="PostingKey" type="xsd:string" nxsd:style="fixedLength" nxsd:length="11" />
<xsd:element name="AdderssKey" type="xsd:string" nxsd:style="fixedLength" nxsd:length="26" />
<xsd:element name="TransactionKey" type="xsd:byte" nxsd:style="terminated" nxsd:terminatedBy="${eol}" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Trailer" nxsd:startsWith="T" minOccurs="1" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FRecords" type="xsd:string" nxsd:style="fixedLength" nxsd:length="9" minOccurs="0"/>
<xsd:element name="DRecords" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
SOA套件11g文件適配器無法解析平面文件,它返回空的XML文檔時,文件中有NULL字符
但當我們用whi替換那些NULL時,事情工作正常。
我們在XSD中是否缺少解析NULL的內容?
是否有任何其他方法來處理NULL?從別人那裏
有什麼辦法逃避NUL字符在將它們轉換爲XML文件時?或給我提示我們如何使用定製Java程序取代NUL – user1589385
您可以隨時編寫一個自定義的InputStream實現來執行過濾。 –