开发者

help with selecting nodes with xpath

开发者 https://www.devze.com 2022-12-23 18:26 出处:网络
my xml structure looks like this: <entity id=\"1000070\"> <name>apple</name> <type>category</type>

my xml structure looks like this:

<entity id="1000070">
    <name>apple</name>
    <type>category</type>
    <entities>
        <entity id="7002870">
            <name>mac</name>
            <type>category</type>
            <entities>
                <entity id="7002907">
                    <name>leopard</name>
                    <type>sub-category</type>
                    <entities>
                        <entity id="7024080">
                            <name>safari</name>
                            <type>subject</type>
                        </entity>
                        <entity id="7024701">
                            <name>finder</name>
                            <type>subject</type>
                        </entity>
                    </entities>
                </entity>
            </entities>
        </entity>
        <entity id="7024080">
            <name>iphone</name>
            <type>category</type>
            <entities>
                <entity id="7024080">
                    <name>3g</name>
                    <type>sub-category</type>
                </entity>
                <entity id="7024701">
                    <name>3gs</name>
                    <type>开发者_运维知识库sub-category</type>
                </entity>
            </entities>
        </entity>
        <entity id="7024080">
            <name>ipad</name>
            <type>category</type>
        </entity>
    </entities>
</entity>

currently i have selected all entities with type node that is not category.

$xmlDocument->removeNodes("//entity[not(type='category')]")

i wonder how i could select all nodes that dont contain type=category OR type=sub-category.

i have tried with:

$xmlDocument->removeNodes("//entity[not(type='category')] | //entity[not(type='sub-category')]")

but it doesnt work!


Try:

//entity[not(type='category' or type='sub-category')]

You may find this testbed for XPath expressions useful.


I think you want:

//entity[not(type='category' or type='sub-category')]

Here's a good (if brief) resource: http://www.w3schools.com/xpath/xpath_operators.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消