the_lotus
the_lotus

Reputation: 12748

Finding elements that don't have an attribute

I'm having trouble finding the syntax that will return the list of UL that do not have an ID attribute.

The following will return Nothing

For Each ul As HtmlAgilityPack.HtmlNode In doc.DocumentNode.SelectNodes("//ul[@id='']")

I know it's possible to return all UL and then to a separate using an If statement, but is there a way for HtmlAgilityPack to return the list of UL that don't have an ID attribute?

Upvotes: 1

Views: 44

Answers (1)

alecxe
alecxe

Reputation: 474031

//ul[not(@id)] will do the trick.

Demo (using xmllint):

$ xmllint index.html --xpath '//ul[not(@id)]/text()'
1
3

where index.html contains:

<div>
    <ul>1</ul>
    <ul id="test">2</ul>
    <ul>3</ul>
</div>

Upvotes: 2

Related Questions