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

Solved. My syntax was wrong.. but very close.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.