Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 3rd, 2018, 12:10 PM
Authorized User
Points: 428, Level: 7
Points: 428, Level: 7 Points: 428, Level: 7 Points: 428, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 94
Thanks: 13
Thanked 0 Times in 0 Posts
Default How do I add/import xml document into another xml document?

I am having trouble adding xml document (CitationDocumentBatch) that is in this object objXMLInputDoc into another object objXMLCopyOfOriginalInputDoc. It should be added as a child of <soapenv:Body>

objXMLInputDoc object contains the following
Code:
CitationDocumentBatch schemaVersion="3:5" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<CitationDocument>
		<Citation>
	</CitationDocument>
</CitationDocumentBatch>
objXMLCopyOfOriginalInputDoc contains the following
Code:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
	<soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	</soap:Header>
	<soapenv:Body>
	<!--Add CitationDocumentBatch here-->
	</soapenv:Body>
</soapenv:Envelope>
The result I want would be in objXMLCopyOfOriginalInputDoc which after I insert/add CitationDocumentBatch from objXMLInputDoc will look like this
Code:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
	<soap:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	</soap:Header>
	<soapenv:Body>
	<CitationDocumentBatch schemaVersion="3:5" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<CitationDocument>
		<Citation>
	</CitationDocument>
</CitationDocumentBatch>
	</soapenv:Body>
</soapenv:Envelope>
Here is what I have tried.
Code:
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"))
I am trying this in vb.net but I am getting an exception "The node to be inserted is from a different document context."
Code:
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"))
Can someone help me with this? It might be very easy but I am not able to figure it out.
Reply With Quote
  #2 (permalink)  
Old August 3rd, 2018, 12:22 PM
Friend of Wrox
Points: 6,666, Level: 34
Points: 6,666, Level: 34 Points: 6,666, Level: 34 Points: 6,666, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,240
Thanks: 0
Thanked 244 Times in 243 Posts
Default

There is an "ImportNode" method for "XmlDocument" you can use e.g.

Code:
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLCopyOfOriginalInputDoc.ImportNode(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"), True))
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
winkimjr2 (August 3rd, 2018)
  #3 (permalink)  
Old August 3rd, 2018, 12:47 PM
Authorized User
Points: 428, Level: 7
Points: 428, Level: 7 Points: 428, Level: 7 Points: 428, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 94
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Thank you so much Martin. I spent time stuck but now it is working!
Reply With Quote
  #4 (permalink)  
Old August 3rd, 2018, 04:30 PM
Authorized User
Points: 428, Level: 7
Points: 428, Level: 7 Points: 428, Level: 7 Points: 428, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 94
Thanks: 13
Thanked 0 Times in 0 Posts
Default How do I include all child elements for inserted document?

My mistake. All I needed to do was use a different object (objXMLParkingCitationsDoc) I do not need help.
The following code inserts xml document but the inserted document does not have all children inside CitationDocumentBatch node.
What do I need to do so all the child elements inside CitationDocumentBatch node are inserted also.

Code:
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLCopyOfOriginalInputDoc.ImportNode(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"), True))

Last edited by winkimjr2; August 3rd, 2018 at 04:58 PM.
Reply With Quote
  #5 (permalink)  
Old August 3rd, 2018, 04:53 PM
Friend of Wrox
Points: 6,666, Level: 34
Points: 6,666, Level: 34 Points: 6,666, Level: 34 Points: 6,666, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,240
Thanks: 0
Thanked 244 Times in 243 Posts
Default

The second argument to "ImportNode" being "True" should ensure a deep copy is imported (https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx) so I can't really see why you say "does not have all children". Can you show a minimal but complete sample of the .NET code and the XMLs to demonstrate the issue, allowing us to reproduce the problem?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #6 (permalink)  
Old August 6th, 2018, 09:22 AM
Authorized User
Points: 428, Level: 7
Points: 428, Level: 7 Points: 428, Level: 7 Points: 428, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 94
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
The second argument to "ImportNode" being "True" should ensure a deep copy is imported (https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx) so I can't really see why you say "does not have all children". Can you show a minimal but complete sample of the .NET code and the XMLs to demonstrate the issue, allowing us to reproduce the problem?
What I meant was, using the object objXMLParkingCitationsDoc worked because that is the object with the information I needed. The original object objXMLInputDoc I used as ImportNode did not have child elements. Thank you again for your help.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to I add xml document to another xml document as a child element? winkimjr2 Visual Studio 2008 0 August 3rd, 2018 10:10 AM
Create an XML document using JAXP and XML fragments. WilliamYou XML 2 October 29th, 2012 04:44 PM
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
add 5 years to date in three nodes in xml document Boris1 XSLT 4 November 25th, 2009 11:18 AM
Add and Remove Nodes in XML document. tutul128 XML 3 March 1st, 2004 10:17 AM



All times are GMT -4. The time now is 08:41 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.