2014-11-19 2 views
1

XPath는 조건을 만족하는 요소를 포함하지 않는 결과 노드를 찾아 반환 할 수 있습니까? 예를 들어 :
나는이있는 경우 :조건을 만족하는 요소를 포함하지 않는 노드에 대한 XPath 쿼리

<ShoppingCenter> 
<bookstore> 
    <book> 
    <year>2005</year> 
    <comments> Boring! </comments> 
    </book> 
</bookstore> 

<bookstore> 
    <book> 
    <year>2005</year> 
    </book> 
</bookstore> 

<bookstore> 
    <book> 
    <year>2005</year> 
    <comments> Interesting! </comments> 
    </book> 
</bookstore> 

</ShoppingCenter> 

나는 결과로 의견 책이없는 경우에만 서점을 좀하고 싶습니다.
이 경우 : 두 번째 가게.

가능합니까? 그리고 만약 그렇다면 어떻게?

답변

1

예, not()를 사용하여 노드의 부재를 확인할 수 있습니다

//bookstore[not(book/comments)] 

데모 (xmllint 사용) :

$ xmllint input.xml --xpath "//bookstore[not(book/comments)]" 
<bookstore> 
    <book> 
    <year>2005</year> 
    </book> 
</bookstore> 
관련 문제