Results 1 to 3 of 3

Thread: How do I add value of a xml node?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    43

    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
    Last edited by winkimjr2; Nov 10th, 2016 at 12:59 PM.

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    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).
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    43

    Re: How do I add value of a xml node?

    Quote Originally Posted by KGComputers View Post
    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).
    Thanks for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width