tags:

views:

9

answers:

0

I am using to ServingXML to parse an xml file which has a format like-

<Accounts>
    <Account>
        ... Some Data ...
        <Invoice>
           ... Some Data ...
               <LineItem>
                   ... Some Data ...
               </LineItem>
               <LineItem>
                   ... Some Data ...
               </LineItem>
        </Invoice>

        <Invoice>
           ... Some Data ...
               <LineItem>
                   ... Some Data ...
               </LineItem>
        </Invoice>
    </Account>

    <Account>
        ... Some Data ...
        <Invoice>
           ... Some Data ...
               <LineItem>
                   ... Some Data ...
               </LineItem>
               <LineItem>
                   ... Some Data ...
               </LineItem>
        </Invoice>

        <Invoice>
           ... Some Data ...
               <LineItem>
                   ... Some Data ...
               </LineItem>
        </Invoice>
    </Account>
</Accounts>

My ServingXML to read the file looks like this-

<sx:inverseRecordMapping id="importFileMapping">
        <sx:onSubtree path="Accounts/Account">
            <!-- Account Data -->
            <sx:flattenSubtree recordType="Account">    
                <sx:subtreeFieldMap select="SomeData1" field="SomeData1" />
                <sx:subtreeFieldMap select="SomeData2" field="SomeData2" />

                <sx:subtreeFieldMap select="Invoice" field="Invoice">        
                    <!-- 
                        Invoice Data 
                        Many Invoice(s) can be associated with one Account
                    -->
                    <sx:flattenSubtree match="Account/Invoice" recordType="Invoice">

                        <sx:subtreeFieldMap select="SomeData3" field="SomeData3" />
                        <sx:subtreeFieldMap select="SomeData4" field="SomeData4" />       
                        <sx:subtreeFieldMap select="LineItem" field="LineItem" recordType="LineItem">                             
                                <!--
                                    Product Data 
                                    Many LineItem(s) or product info can be associated with one Invoice
                                -->
                                <sx:flattenSubtree match="Invoice/LineItem" recordType="LineItem">              
                                    <sx:subtreeFieldMap select="Description" field="ProductDescription"/>
                                    <sx:subtreeFieldMap select="Price" field="ProductPrice"/>
                                    <sx:subtreeFieldMap select="Quantity" field="ProductQuantity"/>
                                </sx:flattenSubtree>            
                        </sx:subtreeFieldMap>
                    </sx:flattenSubtree>
                </sx:subtreeFieldMap>
            </sx:flattenSubtree>
        </sx:onSubtree>
    </sx:inverseRecordMapping>  

If I try reading this using Java, I get a new line and tab delimitted string for "Account/Invoice" like this-

""
"\t\t\tSome Data 3"
"\t\t\tSome Data 4"
"\t\t\t"
"\t\t\t\tSome product desc 1"
"\t\t\t\tSome product price 1"
"\t\t\t\tSome product quantity 1"
"\t\t\t"
"\t\t\t"
"\t\t\t\tSome product desc 2"
"\t\t\t\tSome product price 2"
"\t\t\t\tSome product quantity 2"
"\t\t\t"
"\t\t\t"
etc etc

This format is unexpected as I don't know which LineItem belongs to which Invoice! Any suggestions?