开发者

help with selecting nodes with xpath

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜