Click here to Skip to main content
14,267,938 members

How do I fix VB code not to display empty XML elements from object?

Member 11403304 asked:

Open original thread
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="" xmlns:xsi="" xmlns="">

What I am getting
<InsertPWBRorAOS xmlns:xsd="" xmlns:xsi="" xmlns="">
<DateOfBirth xsi:nil="true"/>
<DateOfDeath xsi:nil="true"/>
<PartyType xsi:nil="true"/>

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="" xmlns:IXML="" PackageID="MMG Updates">
		<CaseEvent xmlns:reslib="urn:reslib" Op="E" Date="06/14/2019" ID="252945068" InternalEventID="1851137356">
			<CompDate Op="E">07/10/2019</CompDate>
			<EventType Word="NOPERWELL">Personal Well-being Report [R]</EventType>
			<PartyID InternalPartyID="536367004">9919636</PartyID>
		<CaseParty ID="9919636" InternalCasePartyID="1655313331" InternalPartyID="536367004">
			<CasePartyName Current="true" ID="10069192" InternalNameID="1615543609">
			<DateOfBirth InternalDOBID="536308471">04/27/1981</DateOfBirth>
		<IntegrationCondition Word="MMGUPD" Description="MMG Updates">
			<NotificationEvent notificationType="MMGUpdate" elementState="Add" elementName="CaseEvent" elementKey="252945068">InsertPWBRorAOS</NotificationEvent>

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)
        'DueDate is RevDate
        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)
        'Count parties in CaseEvent

	intPartiesCount = aobjXmlInputDoc.DocumentElement.SelectNodes("Case/CaseEvent[@ID=" + strEventId + "]/PartyID").Count
        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
End Sub


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

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