I have the following XML and I would like to select the xt:vars
nodes with XPath in PHP.
<xt:locale xmlns:xt="http://www.example.net/xt">
<xt:vars title="Invitation default" type="email" language="EN">
<xt:param name="description">Default invitation mail added to event on creation.</xt:param>
</xt:vars>
<xt:vars title="Einladung" type="email" language="DE">
<xt:param name="description">Einladungsemail</xt:param>
</xt:vars>
</xt:locale>
I am loading the XML file with DOMDocument
and would like to select the nodes with DOMXPath
.
$template_content = file_get_contents($template_file);
$xml = new DOMDocument("1.0", "UTF8");
$xml->preserveWhiteSpace = false;
if ($xml->loadHTML($template_content)){
$xpath = new DOMXPath($xml);
$xpath->registerNamespace('xt', 'http://www.xelos.net/xt');
$query = "//locale/vars[@language='{$language}']";
$entries = $xpath->query($query);
$xmlContent = '';
foreach($entries as $entry) {
$xmlContent = $entry->ownerDocument->saveXML($entry);
}
if ($xmlContent) {
$template_content = $xmlContent;
dump($template_content);
}
}
I am not sure what the correct XPath selector is to grab the correct xt:vars
node.