Parsing huge size xml using XPATH

14 views
Skip to first unread message

imran inamdar

unread,
Nov 9, 2022, 2:33:12 PM11/9/22
to Woodstox User Mailing List
Hi,

We have to read huge xml (10GB) placed at SFTP location. We want to use XPath so that new fields as per requirements in the xml can be fetched without code changes.

The Xml consist of person data :
<Root>
<ORG>
<Person>
..
..
</Person>
...
...
<Person>
...
...
</Person>
...
..
</Org>
</Root>

We are trying to parse the xml as below:

1)Add the Root and Org tag in a list.
2) Start reading the above xml using SAX parser (SAXParser) based on the Person tag.
3) Create a group of 10 person 
4) Create valid xml file with above root and 10 person information.
5) Parse the new xml using DOM parser providing XPath as below
//root/Org/Person/per_id
//root/Org/Person/per_number
//root/Org/Person/PersonAddress/lane
//root/Org/Person/PersonAddress/city
...
....
Keep iterating the org source till all records are scanned.

We cannot directly use XPATH in SAX parser as it will not work. 
We would like to know if the Woodstock will be fast and memory efficient in the above case.


Thanks in advance for any new ideas 

Below is the example snippet of the xml:


<?xml version="1.0" encoding="UTF-8" ?>
<DATA_DS>
    <G_1>
        <PAYROLL_ACTION_ID>61125</PAYROLL_ACTION_ID>
        <G_2>
            <FILE_FRAGMENT>
                <Worker_Extract>
                    <REP_CATEGORY_NAME>anand_restricted1</REP_CATEGORY_NAME>
                    <parameters>
                        <request_id>300000038955960</request_id>
                        <FLOW_NAME>qa233</FLOW_NAME>
                        <legislative_data_group_id/>
                        <effective_date>2022-11-03</effective_date>
                        <start_date/>
                        <report_category_id>300000037130980</report_category_id>
                        <action_parameter_group_id/>
                    </parameters>
                    <Person>
                        <OBJECT_ACTION_ID>1713483</OBJECT_ACTION_ID>
                        <Person_Detail>
                            <PerID>300000001748853</PerID>
                            <PerNumber>12</PerNumber>
                            <PerTypeID>300000000224578</PerTypeID>
                           
                            <Person_Data>
                                <Person_Information>
                                    <PerHistoryPerID>300000001748853</PerHistoryPerID>
                                    <PerHistoryPerNumber>12</PerHistoryPerNumber>
                                    <PerHistoryPerTypeID>300000000224578</PerHistoryPerTypeID>

                                </Person_Information>
                            </Person_Data>
                        </Person_Detail>
                        <Person_Name>
                            <Person_Name_Details>
                                <Person_Name_Detail>
                                    <Per_ID>300000001748853</Per_ID>
                                    <PerNumber>12</PerNumber>
                                    <PerNameBusinessGroupId>1</PerNameBusinessGroupId>
                                    <PerNameCharSetContext>US</PerNameCharSetContext>
                                    <PerDisplayName>Priyanka Jyogi</PerDisplayName>
                                    <PerNameEffectiveStartDate>2019-02-18T00:00:00.000Z</PerNameEffectiveStartDate>
                                    <PerNameEffectiveEndDate>4712-12-31T00:00:00.000Z</PerNameEffectiveEndDate>
                                   
                                    <PerTitle/>
                                </Person_Name_Detail>
                            </Person_Name_Details>
                        </Person_Name>
                        <Person_Phone>
                            <Person_Phone_Details>
                                <Person_Phone_Detail>
                                    <PerNumber>12</PerNumber>
                                    <PerID>300000001748853</PerID>
                                    <PerEffectiveStartDate>2019-02-18T00:00:00.000Z</PerEffectiveStartDate>
                                   
                                </Person_Phone_Detail>
                            </Person_Phone_Details>
                        </Person_Phone>
                        <Person_Email></Person_Email>
                        <Person_NID></Person_NID>
                        <Person_Address></Person_Address>
                        <Person_Legislative_Data>
                            <Person_Legislative_Data_Details>
                                <Person_Legislative_Data_Detail>
                                    <PerID>300000001748853</PerID>
                                    <PerNumber>12</PerNumber>
                                   
                                    <PerLegEffectiveStartDate>2019-02-18T00:00:00.000Z</PerLegEffectiveStartDate>
                                    <PerLegEffectiveEndDate>4712-12-31T00:00:00.000Z</PerLegEffectiveEndDate>
                                    <PerLegGender/>
                                    <PerLegHighestEducatnLevel/>
                                </Person_Legislative_Data_Detail>
                            </Person_Legislative_Data_Details>
                        </Person_Legislative_Data>
                        <Person_Absence></Person_Absence>
                        <Work_Relationship></Work_Relationship>
                    </Person>
                    <Person>
                    ...
                    </Person>
                    <Person>
                    ...
                    </Person>
                    <Person>
                    ...
                    </Person>
                </Worker_Extract>
            </FILE_FRAGMENT>
        </G_2>
    </G_1>
</DATA_DS>
Reply all
Reply to author
Forward
0 new messages