Using PHP, SimpleXML and the xpath() function, I want to select a child node, starting from a certain point. Can you please help me? I know in this specific case I could use an expression starting with "//", but I want to learn the right way of selecting a child node. Thanks.
First try -- fails with Undefined offset: 0 error
$navXmlObject = simplexml_load_file("main_navigation.xml");
$tmpObject = $navXmlObject->website->xpath('title[@lang="fr"]');
echo($tmpObject[0]["label"]);
Second try, adding a slash -- also fails with the same error
$tmpObject = $navXmlObject->website->xpath('/title[@lang="fr"]');
XML file
<?xml version="1.0" encoding="UTF-8"?>
<root>
<website id="MainWeb">
<title lang="fr" label="Mon site Web" />
<title lang="en" label="My web site" />
<menuNodes>
<menuNode id="Home">
<menuNodeData lang="fr" label="Accueil" url="/fr/accueil/" />
<menuNodeData lang="en" label="Home" url="/en/home/" />
</menuNode>
<menuNode id="Prod">
<menuNodeData lang="fr" label="Produits" url="/fr/produits/" />
<menuNodeData lang="en" label="Products" url="/en/products/" />
<menuNode id="Shoe">
<menuNodeData lang="fr" label="Chaussures" url="/fr/produits/chaussures/" />
<menuNodeData lang="en" label="Shoes" url="/en/products/shoes/" />
</menuNode>
</menuNode>
<menuNode id="Biog">
<menuNodeData lang="fr" label="Biographie du fondateur" url="/fr/biographie/" />
<menuNodeData lang="en" label="Biography of founder" url="/en/biography/" />
</menuNode>
</menuNodes>
</website>
</root>