promotion image of download ymail app
Promoted

Reuse the content of XML

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?

更新:

sorry, the code should be:

123

< c >456 < /c >

and

< a >

< b >123< /b >

< c >456 < /c >

< d >789 < /d >

how can I use < xml src="abc.xml" > in def.xml?

更新 2:

I can't type the code here, some errors occur in the syntax

1 個解答

評分
  • 1 十年前
    最愛解答

    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.

    • Commenter avatar登入以回覆解答
還有問題嗎?立即提問即可得到解答。