note 69638 modified in function.simplexml-element-xpath by danbrown

From: Date: Wed, 16 Sep 2009 15:53:35 +0000
Subject: note 69638 modified in function.simplexml-element-xpath by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160691@lists.php.net to get a copy of this message
I was looking to find all of a given element type with attributes which were not of a particular value (including null items). I tried this... <?php $xml->xpath("//pg[@show!='none']"); ?> ...But that only worked if there was in fact some attribute. I thought this should work (shouldn't it?), but it didn't: <?php $xml->xpath("//pg[@show!='none' or !@show]"); ?> The solution is to use the not() function: <?php $xml->xpath("//pg[not(@show='none')]"); ?> --was-- I was looking to find all of a given element type with attributes which were not of a particular value (including null items). I tried this... <?php $xml->xpath("//pg[@show!='none']"); ?> ...But that only worked if there was in fact some attribute. I thought this should work (shouldn't it?), but it didn't: <?php $xml->xpath("//pg[@show!='none' or !@show]"); ?> The solution is to use the not() function: <?php $xml->xpath("//pg[not(@show='none')]"); ?> http://php.net/manual/en/function.simplexml-element-xpath.php

« previous php.notes (#160691) next »