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">
    		<AssociatedValue type="CountyName">
    		<AssociatedValue type="PhoneNumber">

    Result should look like this sample xml

    		<CountyName>MyCounty County</CourtName>

    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"))
    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