please help!
i am parsing html of a site in c#.net and i need to get the img, object, and applet tags from the html to verify if they have alt or longdesc attributes. please help me...

Recommended Answers

All 7 Replies

Please don't make your questions such a puzzle. You mention Regular Expressions in the subject, and "parsing HTML" in the post. You need to "get" certain tags. You need help. There is no question per se in your post. Instead of giving us clues pointing vaguely toward a possible question, why not just ask a clear, specific question?

How, exactly, are you "parsing" the HTML? Are you reading the raw HTML via a Stream? Using an HTML DOM object? What does RegEx have to do with this?

I am reading raw html via a stream and need to look for the tags such as, img, object, and applet to check they have any alt attributes. I am using regular expressions.

i was using this regular expression to find images :
"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work

in other words i would like to match an HTML tag with a certain attribute value.
I am new to regular expression.

>"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work
Erm, why not just this?

private HasAttribute ( string src, string tag, string attribute )
{
  string query = "<" + tag + ".+" + attribute + ".+>";

  //...
}

All you're doing is checking a specific tag to see if it has an alt attribute, right?

I am reading raw html via a stream and need to look for the tags such as, img, object, and applet to check they have any alt attributes. I am using regular expressions.

i was using this regular expression to find images :
"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work

I understand. Regular Expressions are tough and I always resort to trial and error, and use http://www.regular-expressions.info as a good learning resource. RegEx, however, may not be the best approach in this case. RegEx is used to find and even alter strings. I don't think RegEx will solve the problem of finding tags that are missing attributes.

I would use basic string functions for this, searching for my target tag and then searching for the alt attribute within the tag.

I see.
So i should use a regular expressions to find the image, obect, and applet tags, put the tag's contents on a list and parse each one on the list to check if they have the specific attribute?

Is there a regular expression to be able to pull out tags, along with their attributes out of html documents?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.