我想直接获取特定属性的值,而不使用foreach,例如。
我的代码:
$xmldoc = new DOMDocument;
$xmldoc->loadXML($this->Stream);
$xpa = new DOMXPath($xmldoc);
$titles = $xpa->query("//tpd:ParameterSet[@ProcessUsage='Customer']/tpd:Parameter/tpd:CustomerInfo");
foreach ($titles as $title) {
if ($title->hasAttributes()) {
foreach ($title->attributes as $attribute) {
print "AttributName= " . $attribute->name . "\n";
print "AttributValue= " . $attribute->value . "\n";
}
}
到目前为止,它会为您提供输出:
"T:\Program\PHP\php.exe" T:\run.php
AttributName= CustomerID
AttributValue= 1223
AttributName= CustomerOrderID
AttributValue= 1552045326210
Process finished with exit code 0
我的问题: 是否可以直接获取tpd:CustomerInfo / CustomerOrderID的AttributValue?
感谢您的帮助!