Query XPath Select nodes without attribute

Query XPath Select nodes without attribute

Query XPath – Selezionare i nodi che non hanno un attributo

Per selezionare mediante query XPath un insieme di nodi che non hanno un determinato attributo è sufficiente utilizzare l’operatore not:

//book[not(@sold)]

La query selezionerà i nodi “book” che non hanno l’attributo @sold

Ad esempio per l’XML seguente:

<Data> <Books> <book sold="1"> <name>Book 1</name> <price>10</price> </book> <book sold="1"> <name>Book 2</name> <price>81</price> </book> <book> <name>Book 3</name> <price>58</price> </book> <book> <name>Book 4</name> <price>43</price> </book> <book> <name>Book 5</name> <price>54</price> </book> <book> <name>Book 6</name> <price>22</price> </book> </Books> </Data>

la quesry XPath di cui prima selezionerà i nodi Book con Name “Book 3”, “Book 4”, “Book 5”, “Book 6”.

Enjoy snippet!

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *