[yunqa.de] Re: DiHTMLParser and multiple class values

  • From: Gousti Fruit <goustifruit@xxxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Mon, 30 Jan 2012 11:51:19 +0100

Hi,

It's not exactly what I'm looking for: if one class attribute as
several values inside the *same* declaration, the parser will return
the whole string as a single value, though they are several values
inside separated by spaces.
Your example will not work if the p tag is written like this:
<p class="c1 c2">test</p>
-> it will return only one value "c1 c2" for the class attribute.

As a workaround, for now I'm using this "search whole word inside
string" function:

function ExistWordInString(const AString, ASearchString: string;
ASearchOptions: TStringSearchOptions): Boolean;
var
  Size : Integer;
begin
  Size := Length(aString);
  result := SearchBuf(Addr(AString[1]), Size, 0, 0, ASearchString,
ASearchOptions) <> nil;
end;

and in my code, on those tags where I know I can get multiple values:

sTmp := HtmlTag.ValueOfNumber[ATTRIB_CLASS_ID];
if ExistWordInString(sTmp, my_class, [soWholeWord, soDown]) then ...

2012/1/29, Delphi Inspiration <delphi@xxxxxxxx>:
> On 29.01.2012 13:28, Gousti Fruit wrote:
>
>> In my code I'm searching for HTML parts based on some class
>> attributes, like this:
>>
>> if HP.HtmlTag.ValueOfNumber[ATTRIB_CLASS_ID] = some_class then ...
>>
>> but this doesn't work when the class field contains multiple values.
>
> It works, but it only returns the 1st attribute and not all of them.
>
>> For example if I'm searching for all <td class="main"> tags, the
>> parser won't find tags like this: <td class="main first"> or <td
>> class="last main">. Is there an easy way to achieve this with
>> DiHTMLParser ?
>
> You must iterate the attributes manually. See attached sample project
> for an example.
>
> Ralf
>
_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: