473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Using importNode() of Document to add 2 XML docs

An extremely tricky and challenging code.

I have been able to add 2 XML documents together
using importNode().

Expand|Select|Wrap|Line Numbers
  1. xmlDoc1
  2. ----------
  3.  
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <i:Interest xmlns:i="common">
  6. <i:Details xsi.type="i:vanilla.details.stock">
  7.   <i:Strategy xsi.type="strategies:call">
  8.      <strategies.Expiry>2009-12-01</strategies.Expiry>
  9.   </i:Strategy>
  10. <i:Ref/>
  11. </i:Details>
  12. </i:Interest>
  13.  
  14. xmlDoc2
  15. ------------
  16. <?xml version="1.0" encoding="UTF-8"?>
  17. <i:Underlying value="KGF">
  18. <common:Currency>GBP</common:Currency>
  19. </i:Underlying>
  20.  
  21. My Java Code to append them together
  22. -----------------------------------------------------
  23.  
  24. NodeList list = xmlDoc2.getChildNodes();
  25.  
  26. for (int i=0; i< list .getLength(); i++) {
  27.  
  28.      Element element = (Element)list.item(i);
  29.      Node dup = xmlDoc1.importNode(element, true);
  30.  
  31.      xmlDoc1.getDocumentElement().appendChild(dup);
  32. }
  33.  
  34. Output:
  35. ------    
  36. <?xml version="1.0" encoding="UTF-8"?>
  37. <i:Interest xmlns:i="common">
  38. <i:Details xsi.type="i:vanilla.details.stock">
  39.      <strategies.Description>Call</strategies.Description>
  40.      <strategies.Expiry>2009-12-01</strategies.Expiry>
  41.    </i:Strategy>
  42. <i:Ref/>
  43. </i:Details>
  44. <i:Underlying value="KGF">
  45. <common:Currency>GBP</common:Currency>
  46. </i:Underlying>
  47. </i:Interest>    
  48.  
  49.  
  50.  
Query:
I would like to add the 2nd XML Document after element <i:Ref> . How to do this? I dont want the 2nd XML doc after <i:details> but before it.
Please help.
May 3 '07 #1
0 2572

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andy Fish | last post by:
Hi, I have server-based Java application that maintains a fairly large XML structure as a DOM. In response to a user request I want to select various nodes (including sub-nodes) and jam them...
3
by: adam | last post by:
Hi, I'm building a tree control that lazily loads branches of the tree using the document.load() method. The external XML document that is loaded is generated by a servlet as XHTML. What I...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
4
by: peter.staab | last post by:
I have been trying to do the following. Using JS I want to create an input element (text box) and attach a event listener. I have done in in two different ways. The first is using xml elements...
5
by: yawnmoth | last post by:
I wrote the following in an attempt ot better understand importNode: <script> f1=document.createElement("iframe"); f1.src=unescape("http://www.domain.tld/test.txt");...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
3
by: Keith Patrick | last post by:
I'm doing some document merging where I want to bring in an XmlDocument and import its document element into another document deeper in its tree. However, when serializing my underlying objects,...
10
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: ...
5
by: luthriaajay | last post by:
An extremely tricky and challenging code. I have been able to add 2 XML documents together using importNode(). xmlDoc1 ----------
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.