私はphp言語でプログラミングしており、ライブラリSimpleXMLを使用してxmlファイルから言語翻訳を抽出しています。
ファイル「file.xml」からの XML ファイルの抜粋を次に示します。
<language>
<translations>
<string key="key1">This is a first translation</string>
<string key="key2">This is a second translation</string>
</translations>
</language>
ここで、属性「key1」を持つ文字列の xml コンテンツ値 (「これは最初の翻訳です」) を取得したいと考えています。
コードとともに
$xml = simplexml_load_file('file.xml');
$param = $xml->xpath("/language/translations/string[@key='key1']");
私は正しい属性を取得します。しかし、xmlコンテンツ値を取得するために上記のxpathをどのように適合させる必要があるかわかりませんでした。手伝って頂けますか?