Search code examples
xmlxsdflat-file

NULL Appearing in FLAT File, unable to Parse using XSD


We are trying to covert position based FLAT file (https://i.sstatic.net/EryDU.jpg) to valid XML. The file contain Header, Detail Line, Trailer.

Detail Line has data character, whilespace Character and ALSO some other special character like NULL.

NULL character filling one position length. Space also filling one position length.

we have used following XSD to parse this FLAT FILE

                <?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 Suite 11g File adapter is unable to parse the FLAT file, it is returning empty XML document when file has NULL character

But things are working fine when we replace those NULL with whi.

Are we missing anything in the XSD for parsing the NULL ?

Is there any other approach to deal with NULL?

Need guidance from someone out there


Solution

  • Okey, We got the wayout to deal with it,

    We have created Custom Java to replace NUL with whitesapce,

                String fileName =(String)getVariableData("FileName"); 
                String fileLocation =(String)getVariableData("FileLocation"); 
    
                String inputFile = fileLocation + "/" + fileName;
                String outputFile = fileLocation + "/" + fileName + ".temp";
    
                FileInputStream fileInStream = new FileInputStream(inputFile); 
                DataInputStream inputStream = new DataInputStream(fileInStream); 
                BufferedReader bufferRead =  new BufferedReader(new InputStreamReader(inputStream)); 
    
                String stringLine = ""; 
    
                FileWriter fileOutStream = new FileWriter(outputFile); 
                BufferedWriter bufferWrite = new BufferedWriter(fileOutStream); 
    
                    while ((stringLine = bufferRead.readLine()) != null) { 
                        stringLine = stringLine.replaceAll("\0", " "); 
                        bufferWrite.write(stringLine); 
                        bufferWrite.newLine(); 
                    } 
    
                bufferWrite.close(); 
    

    In above code

    stringLine = stringLine.replaceAll("\0", " "); 
    

    will replace the NUL char with witespace