Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2003, 01:48 AM
Authorized User
 
Join Date: Nov 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML Merge...

Hi,

I have 2 XML.
Say I have 2 XMLs,
1: <A><B V='1'/><B V='2'/><B V='3'/></A>
2: <A><B V='4'/><B V='5'/><B V='6'/></A>

I would like to merge them as,
<A><B V='1'/><B V='2'/><B V='3'/><B V='4'/><B V='5'/><B V='6'/></A>

I would like to merge WITHOUT using a loop statement.
Can anyone help me on this.

regds,
Babloo



 
Old November 14th, 2003, 03:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Hi,

this question was answered already: http://p2p.wrox.com/topic.asp?TOPIC_ID=6411

Concerning the looping... Probably not; or you have to write
Code:
importNode(child[0]);
importNode(child[1]);
importNode(child[2]);
:)

Regards,
Armen
 
Old November 14th, 2003, 05:53 AM
Authorized User
 
Join Date: Nov 2003
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
The reply may not suite my problem. Because, the 2 XMLs I had mentioned have m,n childs
So merging the m childs with n childs should be done without looping structure.

Thanks,
Babloo

 
Old November 14th, 2003, 06:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Ok,

you can achieve this with XSLT's xsl:copy-of instruction.
Supposing that your source XML is the first doc you posted and the second is in the file doc2.xml, you can write (not tested):
Code:
<xsl:template macth="A">
 <xsl:copy>
  <xsl:copy-of select="B"/>
  <xsl:copy-of select="document('doc2.xml')/A/B"/>
 </xsl:copy>
</xsl:template>
Without XSLT it's probably impossible (in standard W3C DOM), since in
any case you have to get the node-set from one document and add every node in that nodeset to another (so looping can't be avoided). Or you can use dom4j API (using Node.detach() and Branch.addElement() methods to "transfer" a node from one XML doc to another) and you can avoid looping construct(you get the nodeset using XPath expression, which is really a powerful thing ;)) since the transfer process will be done in so-called event-based mode. So you write event-handlers and you'll never have looping constructs.

Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to merge two xml documents together? NewToXSL Pro VB.NET 2002/2003 2 August 22nd, 2008 05:28 AM
how to merge two records of xml Neha XSLT 6 July 11th, 2008 04:59 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
merge 2 xml documents Beulah VS.NET 2002/2003 0 November 20th, 2003 09:33 PM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.