我遇到了这个问题。我有一个包含以下代码的 xml 文件:
<Products>
<Product>
<ID_Product>1</ID_Product>
<ID_ProductKind>green</ID_ProductKind>
<ID_ProductStatus>apple</ID_ProductStatus>
</Product>
<Product>
<ID_Product>2</ID_Product>
<ID_ProductKind>yellow</ID_ProductKind>
<ID_ProductStatus>banana</ID_ProductStatus>
</Product>
</Products>
现在我想选择ID_ProductKind和ID_ProductStatus,其中ID_Product等于一(1)。无论如何,我的查询结果应该是:
青苹果
这在mysql中是如此简单。如何在 DOMDocument 中执行此操作?
问候大卫
我假设你正在寻找一个基本的XPath表达式。
它不是特别优雅,但你可以尝试这样的东西:"//ID_ProductKind[preceding-sibling::ID_Product='1']/text()"。
您可以使用类似的东西来ID_ProductStatus。
我不太确定连接这些值 - 也许你可以在你的php代码中处理这个问题。 我看到在更高版本的 XPath 中有一个字符串连接函数。