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/>';

    }

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.

thnx blocblue its working perfectly

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.