Advertisement

07.14.2008 at 12:01PM PDT, ID: 23563786
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

What's the best way to handle this?  Working with DOM XPath parsing XML...

Asked by angelleye in PHP Scripting Language

Tags:

I'm working with XML DOM and XPath to parse specific values out of XML data.  When I began my little project I had everything setup like you see at the bottom of my code snippet where I'm simply loading the session variable on a single line and that's it.

What I discovered with this method is that if by chance an element doesn't come back (Address2 is a frequent one) then PHP returns a Notice message that I was trying to load a non existing element.  Of course, that's just a notice, and the code continues to run just fine.

I began to fix the possible notice(s) by changing it to the way you see at the top of my code where I'm loading the element into an object so I can then check the length to see if it exists and only load the variable if it does indeed exist.  

This solves the problem of seeing Notices on the screen, but then I started wondering how much longer this will take my code to run having to go through all these if/else checks vs. simply loading the value.

Would I be better off leaving it the way I had it and turning down the error message settings on my live server so that Notices don't get shown, or should I go ahead and fix my code to avoid all possible Notices and Warnings in cases like this?

Any information would be greatly appreciated.  Thanks!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
$BuyerStreet1 = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:Street1/text()");
if($BuyerStreet1 -> length > 0)
	$_SESSION['BuyerStreet1'] = $BuyerStreet1 -> item(0) -> data;
else
	$_SESSION['BuyerStreet1'] = '';
	
$BuyerStreet2 = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:Street2/text()");
if($BuyerStreet2 -> length > 0)
	$_SESSION['BuyerStreet2'] = $BuyerStreet2 -> item(0) -> data;
else
	$_SESSION['BuyerStreet2'] = '';
	
$BuyerCityName = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:CityName/text()");
if($BuyerCityName -> length > 0)
	$_SESSION['BuyerCityName'] = $BuyerCityName -> item(0) -> data;
else
	$_SESSION['BuyerCityName'] = '';
 
$_SESSION['BuyerStateOrProvince'] = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:StateOrProvince/text()") -> item(0) -> data;
$_SESSION['BuyerPostalCode'] = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:PostalCode/text()") -> item(0) -> data;
$_SESSION['BuyerCountry'] = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:CountryName/text()") -> item(0) -> data;
$_SESSION['BuyerPhoneNumber'] = $eBayItemDataXPath -> query("/ns:GetItemTransactionsResponse/ns:TransactionArray/ns:Transaction/ns:Buyer/ns:BuyerInfo/ns:ShippingAddress/ns:Phone/text()") -> item(0) -> data;
[+][-]07.14.2008 at 12:08PM PDT, ID: 22001009

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 12:29PM PDT, ID: 22001205

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 12:33PM PDT, ID: 22001258

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 12:38PM PDT, ID: 22001312

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 12:41PM PDT, ID: 22001352

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 12:49PM PDT, ID: 22001424

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 02:14PM PDT, ID: 22002196

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: PHP
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628