473,386 Members | 1,702 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,386 software developers and data experts.

Can 2 xml documents be added

I need to add 2 xml documents

1)The first document is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. First.xml
  3. -------------
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
  6.     <Order Acct="MAC" Ccy="USD" ComplianceID="C" >
  7.         <OrdQty Cash="1" Qty="500"/>
  8.     </Order>
  9. </FIXML>
  10.  
  11.  
  12.  
2)The second document is

Expand|Select|Wrap|Line Numbers
  1. Second.xml
  2. ------------------
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <i:Underlying value="KGF" xmlns:common="http://www.tfs.com/equity.derivatives/common" xmlns:i="common">
  5.     <common:Code>KGF</common:Code>
  6.     <common:Class>STOCK</common:Class>
  7. </i:Underlying>
  8.  
  9.  

3) Full output
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4">
  3.     <Order Acct="MAC" Ccy="USD" ComplianceID="C" >
  4.         <OrdQty Cash="1" Qty="500"/>
  5.     </Order>
  6.         <i:Underlying value="KGF" xmlns:common="http://www.tfs.com/equity.derivatives/common" xmlns:i="common">
  7.     <common:Code>KGF</common:Code>
  8.     <common:Class>STOCK</common:Class>
  9.          </i:Underlying>
  10.  
  11. </FIXML>
  12.  
  13.  
I am using Java for this

Expand|Select|Wrap|Line Numbers
  1. Document firstXML.append(Second) 
  2.  
doesnt work as I need to first reach element Order in the first XML
and from that point onwards append the 2nd XML?

Can 2 XML files be added?
May 2 '07 #1
3 1271
dorinbogdan
839 Expert 512MB
Try something like:
Expand|Select|Wrap|Line Numbers
  1. Element root = firstXML.getDocumentElement();
  2. Element root2 = secondXML.getDocumentElement();
  3. root.appendChild(root2);
  4.  
  5. //code to save the final firstXML ...
  6.  
  7.  
For writing the changes see Save XML to file.
May 2 '07 #2
That Doesnt work Dorin (ie using getDocumentElement()).

These are the 2 xmls

Expand|Select|Wrap|Line Numbers
  1.  
  2. DocumentOne 
  3. -----------
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <i:Interest xmlns:i="http://www.ABC.com/interests:i">
  6. <i:ID>0</i:ID><i:Generation/>
  7. <i:Delta/><i:Ref/>
  8. </i:Interest>
  9.  
  10. DocumentTwo
  11. -----------
  12.  
  13. <i:Underlying xmlns:i="common" xmlns:common="http://www.ABC.com/common" value="KGF">
  14.   <common:Code>KGF</common:Code> 
  15.   <common:Class>STOCK</common:Class> 
  16. </i:Underlying>
  17.  
  18.  
  19. Output Format
  20. -------------
  21.  
  22. <?xml version="1.0" encoding="UTF-8"?>
  23. <i:Interest xmlns:i="http://www.ABC.com/interests:i">
  24. <i:ID>0</i:ID><i:Generation/>
  25. <i:Delta/><i:Ref/>
  26. <i:Underlying xmlns:i="common" xmlns:common="http://www.ABC.com/common" value="KGF">
  27.   <common:Code>KGF</common:Code> 
  28.   <common:Class>STOCK</common:Class> 
  29. </i:Underlying>
  30. </i:Interest>
  31.  
  32.  
My Java code is trying to use this

Expand|Select|Wrap|Line Numbers
  1.  
  2. DocumentOne.importNode(DocumentTwo,true)
  3. DocumentOne.replaceChild...
  4.  

Please,has anyone used the above methods?
How can I add both the XML docs?
May 2 '07 #3
dorinbogdan
839 Expert 512MB
If not working with getDocumentElement(), try to get the root elements using a loop like in this example .
May 2 '07 #4

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

Similar topics

5
by: Ken | last post by:
I currently have a set of documents in a directory that i need to list in a html table. Is there any way to generate the table with the documents listed instead of having to update the table...
1
by: switter | last post by:
I am creating a document management systems using asp. I have been researching the different ways of handling the documents such as using the file system and storing the path in the db, and...
4
by: Peter C. Chapin | last post by:
I have a need to include Greek letters in some of my XML documents (the documents contain astronomical information and many stars are named using Greek letters). Following some earlier postings on...
4
by: Luca | last post by:
Hello Everybody, I'm a 26 years old Italian "Florentine" Computer technician :) I'm writing you about an idea that I've got of a function that could be introduced in new web browsers (or even...
1
by: dixie | last post by:
I am trying to send information to 2 different MS Word 2000 documents from automation code in Access 2000. I have simply added an extra transfer text command and an extra line to open the document...
9
by: Thomas Scheiderich | last post by:
I am getting ready to look at putting our users manual and employee handbook on our intranet and was curious how others do it? We have it already set up as Word documents and am looking at...
1
by: Kishor | last post by:
Hi, I have developed an assembly, now it the the time to build the setup for assembly. I have created Setup project. I have added necessary files, created shortcuts... etc. when I started build,...
2
by: SamSpade | last post by:
I'm looking at using a TreeView control and can see how to fill in MyComputer with directory and file names. But I have no idea of how to include things like My Documents and My Network Places ...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.