我有XML的有5个供应商的,我想把这个大文件分成2个供应商的每个文件开始标签和结束标签是这样的,我有5个供应商的.
我看了几篇文章,如果文件大小很大,可以使用StaX解析器,我的文件是( >6GB ),所以如何将示例文件分割成多个文件。
这是我的示例XML文件.
<?xml version="1.0" encoding="UTF-8"?>
<Shop xmlns="http://www.shpAddress.com">
<tab:Product xmlns:tab="http://www.productName.com">
<tab:Suppllier>
<col:Items xmlns:col="http://www.Items.com">
<col:Delivery>
<Prize xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<LastModifiedDate xmlns="">2020-01-28</LastModifiedDate>
</col:Delivery>
</col:Items>
</tab:Suppllier>
<tab:Suppllier>
<col:Items xmlns:col="http://www.Items.com">
<col:Delivery>
<Prize xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<LastModifiedDate xmlns="">2021-02-28</LastModifiedDate>
</col:Delivery>
</col:Items>
</tab:Suppllier>
<tab:Suppllier>
<col:Items xmlns:col="http://www.Items.com">
<col:Delivery>
<Prize xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<LastModifiedDate xmlns="">2022-02-28</LastModifiedDate>
</col:Delivery>
</col:Items>
</tab:Suppllier>
<tab:Suppllier>
<col:Items xmlns:col="http://www.Items.com">
<col:Delivery>
<Prize xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<LastModifiedDate xmlns="">2023-03-28</LastModifiedDate>
</col:Delivery>
</col:Items>
</tab:Suppllier>
<tab:Suppllier>
<col:Items xmlns:col="http://www.Items.com">
<col:Delivery>
<Prize xsi:nil="true" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<LastModifiedDate xmlns="">2024-04-28+05:30</LastModifiedDate>
</col:Delivery>
</col:Items>
</tab:Suppllier>
</tab:Product>
</Shop>发布于 2020-01-29 22:48:33
在StaX中有一堆预期的样板代码。希望可以使用SAXParser/XMLOutputFactory对将其限制2次。
如果XML格式相当稳定,那么还有另一种方法看起来非常简单。简单的regexp可以在<tab:Suppllier>和</tab:Suppllier>标记之间选择文本。其他稳定的部分(XML的开始和结束)可以硬编码并写入新的部分文件。
https://stackoverflow.com/questions/59975010
复制相似问题