This project has moved and is read-only. For the latest updates, please go here.

Selecting node based on attribute / removing unknown attributes

Mar 4, 2013 at 9:58 AM
Hi all ,

"How can we select all the nodes which does not have the specified list of attributes'
                                     OR in other words i can say 
"How can i remove the unwanted attributes

Eg: i have tags say <div><p> and <img>
<div> and <p> tag can have the following attributes
and <img> can have the follwoing
How can i remove if there are any other attributes?

I tried htmldoc.DocumentNode.SelectNodes("//*[not(@id | @styleName | @typeName |@source | @alt)]");

but it is not working as per my need?

Any help will be appriciated!
Mar 4, 2013 at 10:43 AM
I have tried a simple version and it seems to work. can we get a code sample to see whats happening.
            hp.LoadHtml("<tr id=\"test\">sdf<td>5</td>    <td name=\"tess\" ><span id=\"me\">Fifth street</span></td></tr>");

            var tr = hp.DocumentNode.SelectNodes("//*[not(@id | @name)]");
this will return only 1 item in the collection that is a td with the innerText = 5 as expected.

Think something else might be the issue.


Mar 4, 2013 at 10:48 AM
Hi Lee,

As it is the "OR" condition it should return all the 3 nodes
1st td has "id"
2nd td has name and
span has id

I'm i correct ?
Mar 4, 2013 at 11:26 AM
Edited Mar 4, 2013 at 11:32 AM
Hi arsh,

It should return none as it is only to return a node that hasn't got the attribute ID and not got the attribute name.

In XPath the | symbol means and

here is a quick link to show the syntax

they use this sample
//book/title | //book/price

which means return all elements with a title and all elements with a price.

Does think make sense?
Mar 4, 2013 at 11:33 AM
Updated above..
Mar 4, 2013 at 11:45 AM
Oh yes!! I checked the link (

But what should we use for "OR" condition ?

Anyways Thanks for your quick Response.
Mar 4, 2013 at 11:53 AM
Is there any other way to select it? If you give me a sample i might be able to help find one.

if you dont want to post here you can send to me at lee.jeary @gmail,com
Mar 4, 2013 at 12:21 PM
My thinking is that with such a wide search criteria you will get a lot of tags that you don't require.

for example a good search would use a class attribute or maybe all td's inside a table with the name of 'test_table'
in the above example could you not just look for all img's / p's / div's
It might also cause you issues if the developer adds custom attributes to the tag as this would also exclude them from the search.

Mar 6, 2013 at 6:58 AM

But it will be a long looping process., doe's any one knows any option in HAP to achieve this?
Mar 7, 2013 at 6:46 AM
Hi Lee,

Can linq will become an option to get the result ?