Select/remove attributes

Topics: User Forum
Feb 3, 2008 at 1:59 PM
Edited Feb 3, 2008 at 2:06 PM
Hi, this is a great product. Just three notes I've come up with while using it for a project:

1. You seem to be missing a RemoveAttribute method.

2. You seem not to have attributes extend Node. If I use, say

HtmlNodeCollection attributes = el.selectNodes(".//@alt[contains(.,\"pizza\")]");

so that I can change "pizza" to "sandwich" in image alt text, I get a message telling me that attributes can't be in a node collection. Instead I have to do

HtmlNodeCollection images = el.selectNodes(".//img[contains(@alt,\"pizza\")]");

and then set the alt attribute of each of the returned images. This isn't a horrible thing in this example, just less direct, but imagine instead that I wanted to change "pizza.example.com" to "pizza.example.org" in every attribute where it appears, whether a src or an href or a codebase and I wanted to select based on ".//@*[contains(.,\"pizza\")]". I can't. Instead, I have to go the second route--but then, for each element returned, I have to figure out which attribute is the one that contained the pattern that I want to replace. Either that, or instead of using @* I have to go the second route once for each of the individual attributes that might contain a match--@href, @src, etc.

3. How come you collapsed Node and Element, instead of having a distinct HtmlElement type?
Feb 19, 2008 at 3:27 PM
Edited Feb 19, 2008 at 3:27 PM

edgrogan wrote:
Hi, this is a great product. Just three notes I've come up with while using it for a project:

1. You seem to be missing a RemoveAttribute method.
snip

I figured it out: node.Attributes.Remove("foo");