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.
="1.0"="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
objInsertPWBRorAOS.CaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseNumber").InnerText
strEventId = aobjxmlNotificationEventNode.SelectSingleNode("@elementKey").InnerText
objxmlCaseEventNode = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@Op='E' and @ID=" + strEventId + "]")
objInsertPWBRorAOS.CompletedDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/CompDate").InnerText)
objInsertPWBRorAOS.DueDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/RevDate").InnerText)
objInsertPWBRorAOS.EventDate = CDate(aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/EventDate").InnerText)
strEventType = aobjXmlInputDoc.DocumentElement.SelectSingleNode("Case/CaseEvent[@ID=" + strEventId + "]/EventType/@Word").InnerText
objInsertPWBRorAOS.EventType = CType([Enum].Parse(GetType(MMGService.EventTypes), strEventType), MMGService.EventTypes)
intPartiesCount = aobjXmlInputDoc.DocumentElement.SelectNodes("Case/CaseEvent[@ID=" + strEventId + "]/PartyID").Count
objInsertPWBRorAOS.RelatedParties = New MMGService.CaseParty(intPartiesCount - 1) {}
For Each objxmlEventPartyIDNode In aobjXmlInputDoc.DocumentElement.SelectNodes("Case/CaseEvent[@ID=" + strEventId + "]/PartyID")
strPartyID = objxmlEventPartyIDNode.InnerText
objCaseParty = New MMGService.CaseParty()
objCaseParty.PartyId = strPartyID
objInsertPWBRorAOS.RelatedParties(i) = objCaseParty
i += 1
Next
End Sub