Basic xpath question..

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2009
Posts: 2
Reputation: yitzhak is an unknown quantity at this point 
Solved Threads: 0
yitzhak yitzhak is offline Offline
Newbie Poster

Basic xpath question..

 
-1
  #1
Aug 12th, 2009
I'm new to xpath.. probably very simple, but I haven't been able to figure it out. I'm working with the following xml structure:

<item dateExpires="0" doNotPublish="0" manufacturer="" productDetailURL="" id="BKIT1009"  type="2">
    <pricing price="29.99" retailMarkup="0" retailPrice="0" saleMarkDown="0" salePrice="0" saleType="0" stockPrice="29.99" taxableNational="1" taxableRegional="1"/>
    </availability>
    <accessoryGroup>misc</accessoryGroup>
    <name>2 Piece Kit</name>
    <briefDescription>2 Piece Kit</briefDescription>
    <description>2 Piece Kit</description>
    <invoiceDescription>2 Piece Kit</invoiceDescription>
    <moreDetailLink></moreDetailLink>
    <downloadStorage></downloadStorage>
  </item>

Now, I accessed this item from a list of items with xpath using the unique id and the nodeValue for <name> and <accessoryGroup>:

		   $feed = new DomDocument;
		   $feed->load('telusAccessories.xml');
		   $xpath = new DOMXPath($feed);
		  
		   if (count($accessories) > 1)
		   {
		   	  print "<strong>Accessories:</strong><br />";
			  foreach( $accessories as $ID )
			  {    
			   $includes = $xpath->query("/accessories/item[@sku='".$ID."']/accessoryGroup");
			   if (!($includes->item(0)->nodeValue)=="")
					print $includes->item(0)->nodeValue.": ";
			   $includes = $xpath->query("/accessories/item[@sku='".$ID."']/name");  
				if (!($includes->item(0)->nodeValue)=="")
					print $includes->item(0)->nodeValue."<br />";
			  }
	        }
			else
			{
				print "No accessories for selected item.";	
			}

The above code works fine, but when I try to get the attribute "price" from the child <pricing...>, I have a problem. I know it's probably something very simple, given the simplicity of xpath... but I'm retarded and i don't feel like ripping any more hair out. Below is the code that's not working:

$includes = $xpath->query("/accessories/item[@sku='".$ID."']/pricing[@price]");
print $includes->item(0)->nodeValue;

Thanks in advance,

Yitzhak
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 2
Reputation: ticketloot121 is an unknown quantity at this point 
Solved Threads: 1
ticketloot121 ticketloot121 is offline Offline
Newbie Poster

Re: Basic xpath question..

 
0
  #2
Aug 20th, 2009
please give me the details about Xpath what it is tickets
Cheap Sports Concerts and Theater Tickets from the Leading Discount Ticket Agent Online
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 2
Reputation: yitzhak is an unknown quantity at this point 
Solved Threads: 0
yitzhak yitzhak is offline Offline
Newbie Poster

Re: Basic xpath question..

 
0
  #3
Aug 20th, 2009
Solved. My syntax was wrong.. but very close.

$includes = $xpath->query("/accessories/item[@sku='".$ID."']/pricing/@price");
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC