I need help on how to create a variable to hold 3 phone objects (i.e objxmlHomePhone, objxmlCellPhone, objxmlWorkPhone).
My 3 objects are populated from xml document which I have added below.
The problem I have with my vb code is that when the xml document has no phone elements, my output shows empty elements. I do not want to show empty elements.
The following line of code is doing the update and responsible for showing the elements. objUpdateParty.Phones = {objxmlHomePhone, objxmlCellPhone, objxmlWorkPhone}
The For Each code is where I am trying to use a variable for the 3 phone objects. My hope was to be able to check if each phone object has a number. If it does not, then the code updating should ignore that phone object. This is actually where I need help.
Here is output by my code. You can see the first Phone element does not have Type or Number. I do not want this to appear.
="1.0"
<Phones>
<Phone>
<Type xsi:nil="true"/>
</Phone>
<Phone>
<Number>223-789-6654</Number>
<Type>Cell</Type>
</Phone>
<Phone>
<Number>224-178-2222</Number>
<Type>Work</Type>
</Phone>
</Phones>
Here is my Xml document which in vb code is
objXmlPartyNode There are two phone numbers in this xml document.
="1.0"="UTF-8"
<Phone Op="A" Current="true">
<Type Op="A" Word="CELL">Cell</Type>
<Number Op="A">223-789-6654</Number>
</Phone>
<Phone Op="A" Current="true">
<Type Op="A" Word="WORK">Work</Type>
<Number Op="A">224-178-2222</Number>
</Phone>
What I have tried:
Here is code. I am reading an xml document to get the phone numbers
Dim objxmlHomePhone As New MMGService.Phone()
Dim objxmlCellPhone As New MMGService.Phone()
Dim objxmlWorkPhone As New MMGService.Phone()
Dim objxmlPhones() As Object = {objxmlHomePhone, objxmlCellPhone, objxmlWorkPhone}
Dim objxmlPhoneNode As XmlNode
objxmlPhoneNode = objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME']")
If Not objxmlPhoneNode Is Nothing Then
objxmlHomePhone.Type = MMGService.PhoneNumberTypes.Home
If Not objxmlPhoneNode.SelectSingleNode("Number") Is Nothing Then
objxmlHomePhone.Number = objxmlPhoneNode.SelectSingleNode("Number").InnerText
End If
End IF
objxmlPhoneNode = objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='WORK']")
If Not objxmlPhoneNode Is Nothing Then
objxmlWorkPhone.Type = MMGService.PhoneNumberTypes.Work
If Not objxmlPhoneNode.SelectSingleNode("Number") Is Nothing Then
objxmlWorkPhone.Number = objxmlPhoneNode.SelectSingleNode("Number").InnerText
End If
End If
objxmlPhoneNode = objXmlPartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='CELL']")
If Not objxmlPhoneNode Is Nothing Then
objxmlCellPhone.Type = MMGService.PhoneNumberTypes.Cell
If Not objxmlPhoneNode.SelectSingleNode("Number") Is Nothing Then
objxmlCellPhone.Number = objxmlPhoneNode.SelectSingleNode("Number").InnerText
End If
End If
For Each objxmlPhone As Object In objxmlPhones
If Not objxmlPhones Is Nothing Then
objUpdateParty.Phones = {objxmlHomePhone, objxmlCellPhone, objxmlWorkPhone}
End If
Next