none
How do I get element values from one xml document to another? RRS feed

  • General discussion

  • I have a xml I want to get its elements with their values and add them to a new document. I need help with this. Sometimes, the PhoneNumber node may not exist because it is optional. So I will need to check if the node exist before importing it to the new document.

    All these node will be children of CourtLocation node

    Here is the xml my vb code is reading.

    <?xml version="1.0" encoding="utf-8"?>
    <SimpleTypeCompanion enumerates="CourtLocationTextType">
    	<EnumerationValue code="MN010015J">
    		<Text>MyCounty County</Text>
    		<AssociatedValue type="MNCISNodeID">
    			<Text>111</Text>
    		</AssociatedValue>
    		<AssociatedValue type="CountyName">
    			<Text>MyCounty</Text>
    		</AssociatedValue>
    		<AssociatedValue type="PhoneNumber">
    			<Text>800-811-7111</Text>
    		</AssociatedValue>
    	</EnumerationValue>
    </SimpleTypeCompanion>

    Result should look like this sample xml

    <GetCaseInformationResponseMessage>
    	<CourtLocation>
    		<CountyName>MyCounty County</CourtName>
    		<MNCISNodeID>111</MNCISNodeID>
    		<PhoneNumber>800-811-7111</PhoneNumber>
    	</CourtLocation>
    </GetCaseInformationResponseMessage>

    I have tried this in VB.NET


    In VB.NET code the xml is inside an object objXmlSimpleTypeDoc

    'Produce the response message
    objXmlResponseDoc = New XmlDocument
    objXmlResponseDoc.AppendChild(objXmlResponseDoc.CreateElement("GetCaseInformationResponseMessage", aobjXmlNamespaceManager.LookupNamespace("m")))
    'Use CourtCaseHeaderGroup From CaseGetRequest Schema to limit data returned
    objXmlMNCISData = Library.v4.Case.GetIxmlForCaseNumber(strCaseNumber, "CourtCaseHeaderGroup", False)
    aobjBroker.PostMessageWarehouseSnapshot(objXmlMNCISData.OuterXml, "MNCIS Data", 1)
    'Access the CourtLocationTextType simple type. 
    objXmlSimpleTypeDoc = Msc.Integration.CourtXml.Library.v4.SimpleType.GetCompanionFile("CourtLocationTextType")
    'Court location
    objXmlCourtLocationNode = objXmlResponseDoc.CreateElement("CourtLocation", aobjXmlNamespaceManager.LookupNamespace("m"))
    objXmlResponseDoc.DocumentElement.AppendChild(objXmlCourtLocationNode)
    'CourtName
    objXmlCourtLocationNode.AppendChild(objXmlResponseDoc.CreateElement("CourtName", aobjXmlNamespaceManager.LookupNamespace("m")))
    objXmlResponseDoc.ImportNode(objXmlSimpleTypeDoc.SelectSingleNode("EnumerationValue/AssociatedValue/Text"), True)

    Thursday, August 1, 2019 9:21 PM

All replies

  • Hello,

    VSTO doesn't provide anything for processing XML. Instead, take a look at the System.XML namespace which provides standards-based support for processing XML.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Friday, August 2, 2019 7:33 AM