943,689 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4104
  • C# RSS
Apr 24th, 2008
0

regular expressions

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mjzammit is offline Offline
22 posts
since Apr 2008
Apr 24th, 2008
0

Re: regular expressions

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?
Last edited by tgreer; Apr 24th, 2008 at 6:20 pm.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Apr 25th, 2008
0

Re: regular expressions

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mjzammit is offline Offline
22 posts
since Apr 2008
Apr 25th, 2008
0

Re: regular expressions

in other words i would like to match an HTML tag with a certain attribute value.
I am new to regular expression.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mjzammit is offline Offline
22 posts
since Apr 2008
Apr 25th, 2008
1

Re: regular expressions

>"<img.*src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1\\S+))" but it doesnt work
Erm, why not just this?
C# Syntax (Toggle Plain Text)
  1. private HasAttribute ( string src, string tag, string attribute )
  2. {
  3. string query = "<" + tag + ".+" + attribute + ".+>";
  4.  
  5. //...
  6. }
All you're doing is checking a specific tag to see if it has an alt attribute, right?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 25th, 2008
0

Re: regular expressions

Click to Expand / Collapse  Quote originally posted by mjzammit ...
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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Apr 25th, 2008
0

Re: regular expressions

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mjzammit is offline Offline
22 posts
since Apr 2008
Apr 25th, 2008
0

Re: regular expressions

Is there a regular expression to be able to pull out tags, along with their attributes out of html documents?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mjzammit is offline Offline
22 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Get number from line
Next Thread in C# Forum Timeline: how to add database into the while iam deploying.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC