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 - Undefined offset: 0 hatası ile başarısız oluyor
$navXmlObject = simplexml_load_file("main_navigation.xml");
$tmpObject = $navXmlObject->website->xpath('title[@lang="fr"]');
echo($tmpObject[0]["label"]);
Second try, adding a slash - da aynı hata ile başarısız
$tmpObject = $navXmlObject->website->xpath('/title[@lang="fr"]');
XML dosyası
<?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>