Click here to Skip to main content
15,919,423 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can someone please explain to me how to check the CELL phone using the same query that I used to check for the HOME phone in my if statement?
If type HOME is not found I want to get type CELL, if that is not found, I want to get type WORK, if that is not found, I want to find type FAX in that order.
I only want to get one type at a time. The phone for the type must have @Current='true'


What I need to change is the following if statement
if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == 'Cell')

so that I can recheck for the CELL, WORK and FAX using,
XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME']");

I am not sure how to use this in my if statement to check for CELL, WORK and FAX if there was no HOME

C#
XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true' and Type/@Word='HOME']");


Here is my xml
XML
<?xml version="1.0" encoding="UTF-8"?>
<Party ID="14884325" InternalPartyID="1612739531">
	<Phone Current="true">
		<Type Word="FAX">Fax</Type>
		<Number>999-999-9999</Number>
	</Phone>
	<Phone>
		<Type Word="FAX">Fax</Type>
		<Number>999-999-9999</Number>
	</Phone>
	<Phone Current="true">
		<Type Word="HOME">Home</Type>
		<Number>777-777-7777</Number>
	</Phone>
	<Phone>
		<Type Word="HOME">Home</Type>
		<Number>777-777-7777</Number>
	</Phone>
	<Phone Current="true">
		<Type Word="WORK">Work</Type>
		<Number>111-222-0000</Number>
	</Phone>
	<Phone>
		<Type Word="WORK">Work</Type>
		<Number>111-222-0000</Number>
	</Phone>
		<Phone Current="true">
		<Type Word="CELL">Cell</Type>
		<Number>666-666-6666</Number>
	</Phone>
	<Phone>
		<Type Word="CELL">Cell</Type>
		<Number>666-666-6666</Number>
	</Phone>
</Party>


What I have tried:

C#
Boolean blnPhoneFound = true;
            XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true'and Type/@Word='HOME']");
                if (objxmlPhoneNode != null)
                {
                objCaseParty.Phone = new ConservatorService.Phone();

                    objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Home;
                    //blnPhoneFound = true;
                }
                else if (objxmlPhoneNode != null)
                {
                    if (objxmlPhoneNode.SelectSingleNode("Type[@Word='CELL']").InnerText == "Cell")
                    {
                        objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Cell;
                        //blnPhoneFound = true;
                    }
                }
                     if (objxmlPhoneNode != null)
                    {
                        if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Work")
                        {
                            objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Work;
                            blnPhoneFound = true;
                        }
                    }
                      if (objxmlPhoneNode != null)
                        {
                            if (objxmlPhoneNode.SelectSingleNode("Type").InnerText == "Fax")
                            {
                                objCaseParty.Phone.Type = ConservatorService.PhoneNumberTypes.Fax;
                                blnPhoneFound = true;
                            }
                            } //Fax
                      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 
                   }
                }
Posted
Updated 16-Dec-16 4:50am
v8
Comments
F-ES Sitecore 16-Dec-16 9:21am    
If we don't know what the xml looks like we can't suggest how you can read values from it.
[no name] 16-Dec-16 9:38am    
"Cell" is not the same as "CELL"

1 solution

C#
XmlNode objxmlCellNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true'and Type/@Word='CELL']");


In your code the phonenode contains a node that has Type set to WORK so you'll never find a node that has Type of CELL, you need to execute the query from the parent again. Or simply get all Phone nodes in your initial query and from that select either the work node or the cell node.
 
Share this answer
 
Comments
Member 11403304 16-Dec-16 10:42am    
So xml will always have 4 types of phones HOME, CELL, WORK and FAX. I want to always get the HOME type and display it's number. However if that does not exist and or is does not have @Current ='true', then I want to get the type CELL, if that does not exist or it does not have @Current ='true', then I want to get the type WORK if that does not exist or it does not have @Current ='true', then I want to get type FAX.
So I am not sure how to get the type in that order i.e. Get type 1. HOME 2. If HOME not found get type CELL 3. If not found get type WORK 4. If not found get type FAX. I have edited the code to include FAX and WORK
F-ES Sitecore 16-Dec-16 10:47am    
node = get work number
if (node == null)
{
node = get cell number
if (node == null)
{
node = get fax number
}
}
Member 11403304 16-Dec-16 10:54am    
I am not sure how to replace my if statement with what you gave me.
F-ES Sitecore 16-Dec-16 11:05am    
XmlNode objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true'and Type/@Word='HOME']");
if (objxmlPhoneNode == null)
{
objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true'and Type/@Word='CELL']");
}
if (objxmlPhoneNode == null)
{
objxmlPhoneNode = objxmlBasePartyNode.SelectSingleNode("Phone[@Current='true'and Type/@Word='FAX']");
}
Member 11403304 16-Dec-16 11:13am    
Thank you for the help. It is now working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900