Click here to Skip to main content
14,240,044 members
Rate this:
Please Sign up or sign in to vote.
See more:
My vb code is displaying empty elements from XML document that I did not select in the code. The DateOfBirth and DateOfDeath elements are displayed when I run the code. I do not want them displayed.
These elements are inside the object that have the only element I need it's value displayed which is PartyId. The object name is objCaseParty. In my code I am selecting the PartyId from this object. However the DateOfBirth and DateOfDeath are also displayed in the result xml even though I have not selected them in my vb code.
How do I remove these two elements from being displayed?

Expected result
<InsertPWBRorAOS xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<CaseNumber>10-PR-19-125</CaseNumber>
<CompletedDate>2019-07-10T00:00:00</CompletedDate>
<DueDate>2021-06-14T00:00:00</DueDate>
<EventDate>2019-06-14T00:00:00</EventDate>
<EventType>NOPERWELL</EventType>
<RelatedParties>
<CaseParty>
<PartyId>9919636</PartyId>
</CaseParty>
</RelatedParties>
</InsertPWBRorAOS>


What I am getting
<InsertPWBRorAOS xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="">
<CaseNumber>10-PR-19-125</CaseNumber>
<CompletedDate>2019-07-10T00:00:00</CompletedDate>
<DueDate>2021-06-14T00:00:00</DueDate>
<EventDate>2019-06-14T00:00:00</EventDate>
<EventType>NOPERWELL</EventType>
<RelatedParties>
<CaseParty>
<DateOfBirth xsi:nil="true"/>
<DateOfDeath xsi:nil="true"/>
<PartyId>9919636</PartyId>
<PartyType xsi:nil="true"/>
</CaseParty>
</RelatedParties>
</InsertPWBRorAOS>


Here is the xml document vb code is reading.
<?xml version="1.0" encoding="UTF-8"?>
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" PackageID="MMG Updates">
	<Case>
		<CaseEvent xmlns:reslib="urn:reslib" Op="E" Date="06/14/2019" ID="252945068" InternalEventID="1851137356">
			<EventDate>06/14/2019</EventDate>
			<RevDate>06/14/2021</RevDate>
			<CompDate Op="E">07/10/2019</CompDate>
			<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
			<PartyID InternalPartyID="536367004">9919636</PartyID>
		</CaseEvent>
		<CaseParty ID="9919636" InternalCasePartyID="1655313331" InternalPartyID="536367004">
			<CasePartyName Current="true" ID="10069192" InternalNameID="1615543609">
				<NameFirst>Ynne</NameFirst>
				<NameLast>Zeett</NameLast>
			</CasePartyName>
			<DateOfBirth InternalDOBID="536308471">04/27/1981</DateOfBirth>
		</CaseParty>
	</Case>
	<IntegrationConditions>
		<IntegrationCondition Word="MMGUPD" Description="MMG Updates">
			<NotificationEvent notificationType="MMGUpdate" elementState="Add" elementName="CaseEvent" elementKey="252945068">InsertPWBRorAOS</NotificationEvent>
		</IntegrationCondition>
	</IntegrationConditions>
</Integration>


What I have tried:

Option Explicit On
Option Strict On
Imports System
Imports System.Xml
Imports System.Xml.XPath
Imports System.Collections.Generic
Imports System.Net.ServicePointManager

Public Class InsertPWBRorAOS : Inherits MMGUpdates
Public Shared Sub ProcessInsertPWBRorAOS(ByRef aobjBroker As Msc.Integration.MessageBroker.Library.v4.Broker, ByRef aobjXmlInputDoc As System.Xml.XmlDocument, ByVal aobjxmlNotificationEventNode As XmlNode)
        aobjBroker.PostMessageWarehouseInformationalMessage("Processing an InsertPWBRorAOS message", 1)

        Dim objMMGService As MMGService.GuardianServiceClient = GetServiceClient(aobjBroker)
        Dim objInsertPWBRorAOS As MMGService.InsertPWBRorAOS = New MMGService.InsertPWBRorAOS
        Dim objCaseParty As MMGService.CaseParty
        Dim intPartiesCount As Integer
        Dim i As Integer
        Dim strEventId As String
        Dim strPartyID As String
        Dim objxmlEventPartyIDNode As XmlNode
        

        'CaseNumber
        objInsertPWBRorAOS.CaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseNumber").InnerText
        'EventID
        strEventId = aobjxmlNotificationEventNode.SelectSingleNode("@elementKey").InnerText
        'CaseEvent
        objxmlCaseEventNode = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@Op='E' and @ID=" + strEventId + "]")
        'CompletedDate
        objInsertPWBRorAOS.CompletedDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/CompDate").InnerText)
        'DueDate is RevDate
        objInsertPWBRorAOS.DueDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/RevDate").InnerText)
        'EventDate
        objInsertPWBRorAOS.EventDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/EventDate").InnerText)
        'EventType 
        strEventType = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/EventType/@Word").InnerText
        objInsertPWBRorAOS.EventType = CType([Enum].Parse(GetType(MMGService.EventTypes), strEventType), MMGService.EventTypes)
        'Count parties in CaseEvent

	intPartiesCount = aobjXmlInputDoc.DocumentElement.SelectNodes("Case/CaseEvent[@ID=" + strEventId + "]/PartyID").Count
        'RelatedParties
        objInsertPWBRorAOS.RelatedParties = New MMGService.CaseParty(intPartiesCount - 1) {}
        'i = 0

        'Loop through all PartyIDNodes in CaseEvent with ID equal to NotificationEvent's elementKey 
        For Each objxmlEventPartyIDNode In aobjXmlInputDoc.DocumentElement.SelectNodes("Case/CaseEvent[@ID=" + strEventId + "]/PartyID")
            strPartyID = objxmlEventPartyIDNode.InnerText
            objCaseParty = New MMGService.CaseParty()
            objCaseParty.PartyId = strPartyID 'I only want to display PartyID
            objInsertPWBRorAOS.RelatedParties(i) = objCaseParty
            i += 1
        Next
End Sub
Posted
Updated 11-Jul-19 4:17am
v2
Comments
Dominic Burford 11-Jul-19 11:59am
   
Have you stepped through your code to see at what point the DateOfBirth and DateOfDeath elements are added? That's where I would start. Run the code in the debugger and see where the elements get added, and then amend the code accordingly.
Member 11403304 11-Jul-19 12:33pm
   
I am not able to do it. These are inside the object named objCaseParty
objInsertPWBRorAOS.RelatedParties(i) = objCaseParty

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100