求根据已查到的数据list,生成多个xml文件(相互有关系)的算法。请高手帮忙啊解决办法

求根据已查到的数据list,生成多个xml文件(相互有关系)的算法。请高手帮忙啊
问题描述:根据已查到的数据list,本可以递归生成树形xml(多层),如:
<root>
<item   id= "1 "   fatherid= " "   name= "总部 ">
<item   id= "10 "   fatherid= "1 "   name= "分公司1 ">
<item   id= "100 "   fatherid= "10 "   name= "分公司1的子公司1 "   />
<item   id= "101 "   fatherid= "10 "   name= "分公司1的子公司2 "   />
<item   id= "102 "   fatherid= "10 "   name= "分公司1的子公司3 "   />
</item>
<item   id= "11 "   fatherid= "1 "   name= "分公司2 "   />
<item   id= "12 "   fatherid= "1 "   name= "分公司3 "   />
</item>
</root>
现在的问题是,怎么根据这个list,生成象如下多个文件:
1.main.xml
<root>
<item   id= "1 "   fatherid= " "   name= "总部 "/>
</root>
2.zongbu.xml
<root>
<item   id= "10 "   fatherid= "1 "   name= "分公司1 "/>
<item   id= "11 "   fatherid= "1 "   name= "分公司2 "   />
<item   id= "12 "   fatherid= "1 "   name= "分公司3 "   />
</root>
3.fen1.xml
<root>
<item   id= "100 "   fatherid= "10 "   name= "分公司1的子公司1 "   />
<item   id= "101 "   fatherid= "10 "   name= "分公司1的子公司2 "   />
<item   id= "102 "   fatherid= "10 "   name= "分公司1的子公司3 "   />
</root>

------解决方案--------------------
这要用DOM。
------解决方案--------------------
建议在每个上级xml都加入下级xml的文件名,或者是在另外一个地方存放对应关系,方便自解析