Мой код vb отображает пустые элементы из документа XML, которые я не выбрал в коде. Элементы DateOfBirth и DateOfDeath отображаются, когда я запускаю код. Я не хочу, чтобы они отображались.
Эти элементы находятся внутри объекта, у которого есть единственный элемент, который мне нужен, это отображаемое значение - PartyId. Имя объекта - objCaseParty. В моем коде я выбираю PartyId из этого объекта. Однако DateOfBirth и DateOfDeath также отображаются в результирующем xml, хотя я не выбрал их в своем коде vb.
Как убрать эти два элемента с экрана?
Ожидаемый результат
<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>
Что я получаю
<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>
Вот код vb xml документа, который читает.
<?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>
Вот мой код vb.net
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
**Someone asked me to add how serialization is done i.e. class**
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0"), _
System.Runtime.Serialization.DataContractAttribute(Name:="CaseParty", [Namespace]:="http://schemas.datacontract.org/2004/07/MyMNGuardian.Services.DataContracts"), _
System.SerializableAttribute()> _
Partial Public Class CaseParty
Inherits Object
Implements System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged
<System.Runtime.Serialization.OptionalFieldAttribute()> _
Private DateOfBirthField As System.Nullable(Of Date)
<System.Runtime.Serialization.OptionalFieldAttribute()> _
Private DateOfDeathField As System.Nullable(Of Date)
<System.Runtime.Serialization.DataMemberAttribute()> _
Public Property DateOfBirth() As System.Nullable(Of Date)
Get
Return Me.DateOfBirthField
End Get
Set
If (Me.DateOfBirthField.Equals(value) <> true) Then
Me.DateOfBirthField = value
Me.RaisePropertyChanged("DateOfBirth")
End If
End Set
End Property
<System.Runtime.Serialization.DataMemberAttribute()> _
Public Property DateOfDeath() As System.Nullable(Of Date)
Get
Return Me.DateOfDeathField
End Get
Set
If (Me.DateOfDeathField.Equals(value) <> true) Then
Me.DateOfDeathField = value
Me.RaisePropertyChanged("DateOfDeath")
End If
End Set
End Property
End Class