当前位置: 代码迷 >> ASP.NET >> 100分送出去!求XML循环递归添加子节点有关问题
  详细解决方案

100分送出去!求XML循环递归添加子节点有关问题

热度:330   发布时间:2013-02-26 00:00:00.0
100分送出去!求XML循环递归添加子节点问题
a.xml,无子节点

<?xml   version= "1.0 "   standalone= "yes "?>
<Structrue>
    <Departments>
        <Department   DWBM= "115600200101 "     SJDWBM= "geotech "/>
        <Department   DWBM= "100300200601 "   SJDWBM= "115600200101 "   />
        <Department   DWBM= "200000200601 "     SJDWBM= "115600200101 "   />
          <Department   DWBM= "100300200601 "     SJDWBM= "115600200101 "   />
        <Department   DWBM= "200000200601 "     SJDWBM= "115600200101 "   />
        <Department   DWBM= "168200200201 "   SJDWBM= "100300200601 "   />
        <Department   DWBM= "188700200301 "     SJDWBM= "100300200601 "   />
        <Department   DWBM= "188700200302 "   SJDWBM= "188700200301 "   />
        <Department   DWBM= "188700200303 "     SJDWBM= "188700200301 "   />
        <Department   DWBM= "188700200501 "   SJDWBM= "188700200301 "   />
        <Department   DWBM= "151200200301 "   SJDWBM= "100300200601 "   />
        <Department   DWBM= "151200200302 "     SJDWBM= "151200200301 "   />
        <Department   DWBM= "226600200301 "   SJDWBM= "200000200601 "   />
        <Department   DWBM= "226600200401 "     SJDWBM= "226600200301 "   />
    </Departments>
</Structrue>

现在根据 "SJDWBM "和 "DWBM "两个属性值来判断,如果a节点 "SJDWBM "的值和b节点的 "DWBM "值相同,则a节点为b节点的子节点。
最终得到b.xml文件,
b.xml

<?xml   version= "1.0 "   standalone= "yes "?>
<Structrue>
    <Departments>
        <Department   DWBM= "115600200101 "       SJDWBM= "geotech ">
            <Department   DWBM= "100300200601 "     SJDWBM= "115600200101 "   >
<Department   DWBM= "168200200201 "     SJDWBM= "100300200601 "   />
<Department   DWBM= "188700200301 "     SJDWBM= "100300200601 "   >
        <Department   DWBM= "188700200302 "     SJDWBM= "188700200301 "   />
<Department   DWBM= "188700200303 "     SJDWBM= "188700200301 "   />
<Department   DWBM= "188700200501 "   SJDWBM= "188700200301 "   />
</Department>
<Department   DWBM= "151200200301 "     SJDWBM= "100300200601 "   >
<Department   DWBM= "151200200302 "     SJDWBM= "151200200301 "   />
</Department>
      </Department>
  相关解决方案