我有以下格式的 XML 文档:
<CONFIGURATION>
<ADMIN REFERRER="BCTRD" REQUIRE_AGREEMENTS="true" ALLOW_UPGRADES="true" />
<LAYOUT HIDE_PRESELECTED_SERVICES="true" AGREEMENTS_PER_EXCHANGE="true"></LAYOUT>
<SERVICE ID="TRE" CODE="TRADER_EMINI" OPTIONAL_BROKER="true">
<EXCHANGE GROUP="FOO"/>
</SERVICE>
<SERVICE ID="TR" CODE="TRADER">
<DEFAULT/>
<EXCHANGE GROUP="BAR"/>
</SERVICE>
</CONFIGURATION>
我目前正在使用此代码块来检索默认服务的服务代码:
$serviceList = $this->xpaths->query('config',"//SERVICE");
foreach ($serviceList as $service) {
if ($service->getElementsByTagName('DEFAULT')->length) {
$serviceCode = $service->attributes->getNamedItem('CODE')->nodeValue;
break;
}
}
我怀疑用一两行 XPath 可以做到这一点,但我不知道怎么做。您将如何格式化 XPath 查询来检索我所追求的服务代码?