How do I add value of a xml node?
Basically what I want to do is add objXMLPartyIDValuesDoc Case/s to aobjXmlInputDoc after the IntegrationConditions element
I would like to loop through each Case in objXMLPartyIDValuesDoc and then append Case to aobjXmlInputDoc after IntegrationConditions element.
I know I have to use import and append but I am not sure how.
Here is the aobjXMLInputDoc and is where I want to add the Case/s after IntegrationConditions element.
aobjXmlInputDoc
Code:
<Integration>
<IntegrationConditions>
<IntegrationCondition Word="Something" Description="Nothing"/>
</IntegrationConditions>
<!--Add the case elements here.-->
</Integration>
Here is the objXMLPartyIDValueDoc which contains two cases. Sometimes there will be only one case. sometimes there will be many cases.
objXMLPartyIDValuesDoc with two cases.
Code:
<Cases>
<Case>
<Court>
<NodeID>8</NodeID>
</Court>
<CaseType Word="XYZ">Something</CaseType>
<BaseCaseType>Adult</BaseCaseType>
<CaseCategory>CR</CaseCategory>
<Connection Word="VIC" BaseConnection="VI">Victim</Connection>
</Case>
<Case>
<Court>
<NodeID>01</NodeID>
</Court>
<CaseType Word="DFT">Default Judgment</CaseType>
<BaseCaseType>Bond Forfeiture</BaseCaseType>
<CaseCategory>CV</CaseCategory>
<Connection Word="PLN" BaseConnection="PL">Plaintiff</Connection>
</Case>
</Cases>
Expected result should look like this
Code:
<Integration>
<IntegrationConditions>
<IntegrationCondition Word="Something" Description="Nothing">
</IntegrationCondition>
</IntegrationConditions>
<Cases>
<Case>
<Court>
<NodeID>8</NodeID>
</Court>
<CaseType Word="XYZ">Something</CaseType>
<BaseCaseType>Adult</BaseCaseType>
<CaseCategory>CR</CaseCategory>
<Connection Word="VIC" BaseConnection="VI">Victim</Connection>
</Case>
<Case>
<Court>
<NodeID>01</NodeID>
</Court>
<CaseType Word="DFT">Default Judgment</CaseType>
<BaseCaseType>Bond Forfeiture</BaseCaseType>
<CaseCategory>CV</CaseCategory>
<Connection Word="PLN" BaseConnection="PL">Plaintiff</Connection>
</Case>
</Cases>
</Integration>
My incomplete vb code
Code:
'Run SQL query uaing function GetCaseSQL
Dim strSql As String = GetCaseSQL(aobjXmlInputDoc.DocumentElement.SelectSingleNode("/Integration/PartyMerge/TargetInternalPartyID").InnerText)
'Query Justice database using the query strSql
Dim objXMLPartyIDValuesDoc As XmlDocument = Msc.Integration.Mncis.Library.v4.Odyssey.QueryDB(strSql, "Justice", False, True)
'Loop through each case in objXMLPartyIDValuesDoc
Dim CaseNode As XmlNodeList = objXMLPartyIDValuesDoc.SelectNodes("Cases/Case")
'For Each
'Code Add case to aobjXmlInputDoc
'Next
Re: How do I add value of a xml node?
Here's how to iterate through XmlNodeList.
looping through XML file using VB.NET
Append element to XML
Write or append the Element to XML file using XmlDocument
For saving XML document, write doc.Save("your_xmlfile") instead of doc.Save(Console.Out).
Re: How do I add value of a xml node?
Quote:
Originally Posted by
KGComputers
Thanks for your help.