Results 1 to 2 of 2

Thread: How do I display Home phone from xml doc?

  1. #1
    momokesh is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2016
    Posts
    1
    Reputation
    0

    How do I display Home phone from xml doc?

    My C# code is returning the first phone number in the xml document regardless of its type.
    But the requirement is that my C# code should return only one phone number based on type found in xml document in a certain order.
    There are 4 types of phone numbers as you will see in the xml document code I have posted here below.
    The condition to display the phone number by type is as follows:
    1. Check in the xml for Phone Current ="true". After that display the phone number where Type Word ="HOME" first. If this type is not found, look for Type Word ="CELL" and display it. If this is not found then look for Type Word ="WORK" and display it. If all above Types are not found look for Type Word="FAX" and display the fax number.
    There will always be at least one phone current number with a type

    xml document
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Integration> 
     <Party ID="1">
      <Phone>
       <Type Word="WORK">Work</Type>
       <Number>218-222-2222</Number>
      </Phone>
      <Phone Current="true"> 
       <Type Word="FAX">Fax</Type>
       <Number>218-777-7777</Number>
      </Phone>
      <Phone>
       <Type Word="HOME">Home</Type>
       <Number>218-333-3333</Number>
      </Phone>
      <Phone>
       <Type Word="CELL">Cell</Type>
       <Number>218-555-5555</Number>
      </Phone>
      <Phone Current="true">
       <Type Word="CELL">Cell</Type>
       <Number>218-666-6666</Number>
      </Phone>
      <Phone Current="true">
       <Type Word="HOME">Home</Type>
       <Number>218-300-0011</Number>
      </Phone>
      <Phone Current="true">
       <Type Word="WORK">Work</Type>
       <Number>218-111-0000</Number>
      </Phone>
      <Phone> 
       <Type Word="FAX">Fax</Type>
       <Number>218-000-9999</Number>
      </Phone>
    </Integration>
    C# code
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    namespace Msc.Integration.Mncis.Service.v4
    {
        class InsertUpdateCase : CamperUpdates
        {
            public void ProcessInsertUpdateCase(ref Msc.Integration.MessageBroker.Library.v4.Broker aobjBroker, ref System.Xml.XmlDocument aobjXmlInputDoc, ref Microsoft.VisualBasic.Collection aobjInstantiatedObjectsCollection, XmlNode aobjxmNotificationEventNode)
            /// <summary>
            /// </summary>
            /// <param name="objxmlBasePartyNode"></param>
            /// <param name="objxmlCasePartyNode"></param>
            /// <param name="objxmlBasePartyAddressNode"></param>
            /// <param name="objCaseParty"></param>
            protected void GetParty(ref XmlNode objxmlBasePartyNode, XmlNode objxmlCasePartyNode, ref XmlNode objxmlBasePartyAddressNode, ref ConservatorService.CaseParty objCaseParty, string astrDescription)
            {        
                objCaseParty.PartyId = objxmlBasePartyNode.SelectSingleNode("@ID").InnerText;
                objCaseParty.PartyType = (ConservatorService.MncisPartyTypes)Enum.Parse(typeof(ConservatorService.MncisPartyTypes), astrDescription);
                Boolean blnPhoneFound = false;
                XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true']");
                if (objxmlPhoneNode != null)
                {
                    objCaseParty.Phone = new ConservatorService.Phone();
                    if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Home")
                    {
                        objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Home;
                        blnPhoneFound = true;
                    }
                    else //Cell
                    {
                        if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Cell")
                        {
                            objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Cell;
                            blnPhoneFound = true;
                        }
                        else //Work
                        {
                            if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Work")
                            {
                                objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Work;
                                blnPhoneFound = true;
                            }
                            else //Fax
                            {
                                if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Fax")
                                {
                                    objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Fax;
                                    blnPhoneFound = true;
                                }
                            } //Fax
                        } //Work
                    } // Cell
                    if (blnPhoneFound)
                    {
                        if (objxmlPhoneNode.SelectSingleNode("Extension") != null)
                        {
                            string strExtension = objxmlPhoneNode.SelectSingleNode("Extension").InnerText;
                            objCaseParty.Phone.Extention = strExtension;
                        }
                        if (objxmlPhoneNode.SelectSingleNode("Number") != null)
                        {
                            string strNumber = objxmlPhoneNode.SelectSingleNode("Number").InnerText;
                            objCaseParty.Phone.Number = strNumber;
                        }
                    }
                } //Phone Current 
           
            }
        }
    }
    Last edited by momokesh; 12-13-2016 at 11:55 AM. Reason: added text in bold

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,068
    Reputation
    2801
    VB.Net Forums that this place is called is for VB.Net development only. I recommend C# Forums for C# related development. Thread is therefore closed.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •