简体   繁体   中英

XML DOMDocument php - query

I've got this problem. I have an xml file which contains this code:

<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>

Now I would like to select ID_ProductKind and ID_ProductStatus where ID_Product is equal to one(1). Anyway the result of my query should be:

green apple

It's so simple in mysql. How can I do this in DOMDocument?

Regards, David

I assume you're looking for a basic XPath expression.

It's not particularly elegant, but you might try something like this: "//ID_ProductKind[preceding-sibling::ID_Product='1']/text()".

You can use something similar for ID_ProductStatus.

I'm not quite sure about concatenating the values -- perhaps you can handle this in your php code. I see that there's a string-join function in later versions of XPath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM