none
How do I create a new XML document and add elements with their value from another XML document RRS feed

  • Question

  • I want to create a new xml document named objXmlResponseDoc and add two elements from an existing xml document named

    Here is the xml document I want to get the values from. It is named objXmlSimpleTypeDoc

    <SimpleTypeCompanion>
    	<EnumerationValue code="DC19DAKDC">
    		<Text>Dakota County</Text>
    		<AssociatedValue type="MNCISNodeID">
    			<Text>112</Text>
    		</AssociatedValue>
    	</EnumerationValue>
    </SimpleTypeCompanion>

    Here is the new xml document I want to create

    <GetCaseInformationResponseMessage>
    	<CourtLocation>
    		<CourtName>Dakota County</CourtName>
    		<MNCISNodeID>112</MNCISNodeID>
    	</CourtLocation>
    </GetCaseInformationResponseMessage>

    Here is VB.NET code

    'Produce the response message
    objXmlResponseDoc = New XmlDocument
    objXmlResponseDoc.AppendChild(objXmlResponseDoc.CreateElement("GetCaseInformationResponseMessage"))
    
    'Court location
    objXmlCourtLocationNode = objXmlResponseDoc.CreateElement("CourtLocation")
    objXmlResponseDoc.DocumentElement.AppendChild(objXmlCourtLocationNode)
    
    'CourtName    
    objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("CourtName"))
    objXmlResponseDoc.ImportNode(objXmlSimpleTypeDoc.SelectSingleNode("EnumerationValue/Text"))

    Friday, August 2, 2019 4:17 PM

All replies