0

hi to all m lil bit confuse as m beginner to the xml+xpath. so m sorry if i m unable to ask any kind of wrong question.

now the question is m trying to accessing the name of the of the attribute of xml file using xpath and tyring to print it on the screen using php but m unable to do...

here is the xml statement for which m trying

    <product>
    <price currency="EUR">9.95</price>
    <productURL>http://www.example.com</productURL>
    <imageURL>http://www.example.com/store/images/products/medium/9789033634628.jpg</imageURL>
    <description>Not Available</description>
    <categories>
    <category path="Nederlands / Religie &amp; Spiritualiteit / Religie /"></category>
    </categories>
    </product>

as i want to print out the following attribute name:
Nederlands / Religie &amp; Spiritualiteit / Religie /
for the other information i have done the job but for accessing the category m unable to do so...plz help out me to access the category name.
following is my work done for accessing the mentioned category.

$cat = $xml->xpath("/product[1]/categories/category");
foreach($cat as $category)
    {
        echo 'Category:';
        echo $category.'<br/>';

    }
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by shahai.ali
1

In your example, the category data is stored in an attribute, rather than within the node itself.

You therefore need to use the XPath: /product[1]/categories/category/@path where the @ shows you want to target an attribute.

0

thnx blocblue its working perfectly

Edited by shahai.ali

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.