Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having trouble adding CitationDocumentBatch element that is in this object objXMLInputDoc. I want to add it to this object objXMLCopyOfOriginalInputDoc. It should be added as a child of <soapenv:body> inside objXMLCopyOfOriginalInputDoc.

objXMLInputDoc object contains the following
XML
<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" xsi:schemaLocation="http://www.courts.state.mn.us/CourtXML/3 file:///H:/Deve/Schemas/CourtXML/CitationDocument_3_5.xsd">
	<CitationDocument>
		<Citation>
	</CitationDocument>
</CitationDocumentBatch>


objXMLCopyOfOriginalInputDoc contains the following
XML
<?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 or insert CitationDocumentBatch element 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
XML
<?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" xsi:schemaLocation="http://www.courts.state.mn.us/CourtXML/3 file:///H:/Deve/Schemas/CourtXML/CitationDocument_3_5.xsd">
	<CitationDocument>
		<Citation>
	</CitationDocument>
</CitationDocumentBatch>
	</soapenv:Body>
</soapenv:Envelope>


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.

What I have tried:

I have tired this but I am getting an exception
VB
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"))
Posted
Updated 3-Aug-18 5:53am
v3
Comments
Richard MacCutchan 3-Aug-18 4:47am    
"I am getting an exception "Object reference not set to an instance of an object.""
You need to use your debugger to find out why that reference variable is null instead of a valid reference.
Member 11403304 3-Aug-18 9:37am    
Actually the exception is "The node to be inserted is from a different document context"

You need to import the node.

C#
XmlNode node = objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch");

XmlNode copiedNode = objXMLCopyOfOriginalInputDoc.OwnerDocument.ImportNode(node, true); //needs to import node, true = if you want deep copy


objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(copiedNode);
 
Share this answer
 
v3
Comments
Member 11403304 3-Aug-18 10:28am    
what is this for var node =? When I convert it to vb.net Dim node As var = I get an error for var that 'Type var is not defined.'
Keviniano Gayo 3-Aug-18 11:35am    
XmlNode node...
I no longer need help. I used "ImportNode" method for XmlDocument
VB
objXMLCopyOfOriginalInputDoc.DocumentElement.SelectSingleNode("soap:Body", objXMLNameSpaceManager).AppendChild(objXMLCopyOfOriginalInputDoc.ImportNode(objXMLInputDoc.SelectSingleNode("//CitationDocumentBatch"), True))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900