Reuse the content of XML

2006-12-21 12:35 am
If I have the xml file called "abc.xml" which has the following contents:

<a rel=\"nofollow\">
<b>123</b>
456
</a>
and I have another xml called &quot;def.xml&quot; and I want the contents of abc.xml merage with def.xml, such that:

<a rel=\"nofollow\">
<b>123</b>
456
789
</a>

What code should I add into the def.xml?

回答 (1)

2006-12-21 1:58 am
✔ 最佳答案
You can not simply add code to def.xml and merge them, you&#39;ll need to write a program to merge them, i.e. using a DOM object.

You final xml example is syntatically incorrect, it should be:
<a rel="nofollow">
<b>123</b>
<b>456</b>
<b>789</b>
</a>

Basically you need to sort the Bs in order for each xml, read the abc.xml to create a DOM object, read the def.xml and then compare them; if &#39;b&#39; from def.xml not in abc.xml, append it to abc DOM. Once merging completed you can out put abc DOM as the resulting xml.


收錄日期: 2021-04-13 15:57:04
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061220000051KK02003

檢視 Wayback Machine 備份