Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge 2 XML trees

Status
Not open for further replies.

inza141

Programmer
Jan 25, 2006
5
NL
I can create the following XML with datatables en datarelations:

<DT1>
<DT2 Test="Test1">
<DT3>
<DT4 Test="Test1" />
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT3>
</DT2>
<DT2 Test="Test4">
<DT3>
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT4 Test="Test4" />
<DT3>
</DT2>
</DT1>

But now i want to add another root tree <DT1> with another name like <DT5>. Like this:

<DT1>
<DT2 Test="Test1">
<DT3>
<DT4 Test="Test1" />
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT3>
</DT2>
<DT2 Test="Test4">
<DT3>
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT4 Test="Test4" />
<DT3>
</DT2>
</DT1>
<DT5>
<DT2 Test="Test1">
<DT3>
<DT4 Test="Test1" />
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT3>
</DT2>
<DT2 Test="Test4">
<DT3>
<DT4 Test="Test2" />
<DT4 Test="Test3" />
<DT4 Test="Test4" />
<DT3>
</DT2>
</DT5>

How can I do this?
Can I merge 2 xml files?

Greetings.

Lexie.


 
If by DT5 you meant to be a mirror copy of DT1 as well, then can do it like this.
[tt]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="xml" indent="yes" />
<xsl:template match="/">
<xsl:element name="root">
<xsl:element name="DT1">
<xsl:copy-of select="DT1/*" />
</xsl:element>
<xsl:element name="DT5">
<xsl:copy-of select="DT1/*" />
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
XML can have exactly one root element, thus you'll need to put another layer in:
Code:
<root>
  <DT1>
  ......
  </DT1>
  <DT5>
  ......
  </DT5>
</root>
By the way, XML is supposed to be human-readable. That example makes no sense to me (although it may be sensible).

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top