[yunqa.de] Re: missing the '=' in tag attribute with empty value after deletion another attribute

  • From: Кудрявцев Дмитрий <d.v.k@xxxxxxx>
  • To: Delphi Inspiration <yunqa@xxxxxxxxxxxxx>
  • Date: Thu, 26 Apr 2012 19:01:28 +0700

Title: Re: [yunqa.de] Re: missing the '=' in tag attribute with empty value after deletion another attribute
Thank you very much.

Thursday, April 26, 2012, 6:47:16 PM, you wrote:

DI> On 25.04.2012 05:18, Кудрявцев Дмитрий wrote:

>> I  use  TDIHtmlParser with TDIHtmlWriterPlugin and found the following
>> strange result when processing tags:
>> if  tag  has two attributes: first is empty (e.g. title=""), second is
>> not  empty  (e.g.  href=""),  then  deletion  of second attribute
>> causes that 1st (empty) attribute loses the ="" part and become in our
>> example simple "title" (without quotes).
>> May be it is not correct?

DI> Yes, this is correct in HTML terms. An attribute without a value is just
DI> like the attribute with an empty value:

DI>   
http://www.w3.org/TR/html-markup/syntax.html#syntax-attr-empty

>> The DIHtmlWriterPlugin1.QuoteHtmlTags := qtAlways; does not helps.

DI> You can force to write out empty attribute values by specifying

DI>   DIHtmlWriterPlugin1.EmptyHtmlAttribValues := True;

DI> To demonstrate this, I have copied an example project below.

DI> Ralf

DI> {-------------------------------------------------------------------------------

DI>   DIHtmlParser project to demonstrate how to force TDIHtmlWriterPlugin
DI>   to always write out quoted empty attribute values.

DI>   Visit the DIHtmlParser homepage for latest information and updates:

DI>     
http://www.yunqa.de/delphi/

DI>   Copyright (c) 2012 Ralf Junker, The Delphi Inspiration <delphi@xxxxxxxx>

DI> -------------------------------------------------------------------------------}

DI> program WriterPlugin_2;

DI> {$APPTYPE Console}

DI> uses
DI>   {$IFDEF FastMM}{$I FastMM_uses.inc}{$ENDIF}
DI>   DISystemCompat, DIHtmlMisc, DIHtmlParser, DIHtmlWriterPlugin;

DI> const
DI>   HTML: RawByteString = '<a title="" href="">';
DI> var
DI>   HP: TDIHtmlParser;
DI>   HW: TDIHtmlWriterPlugin;
DI> begin
DI>   {$IFDEF FastMM}{$I FastMM_init.inc}{$ENDIF}

DI>   HP := TDIHtmlParser.Create(nil);
DI>   HW := TDIHtmlWriterPlugin.Create(nil);
DI>   try
DI>     HW.HtmlParser := HP;

DI>     HP.SetAllFilters(fishow);
DI>     HP.SourceBufferAsStrA := HTML;

DI>     { Always write out quoted empty attribute values. }
DI>     HW.EmptyHtmlAttribValues := True;
DI>     HW.QuoteHtmlTags := qtAlways;

DI>     while HP.ParseNextPiece do
DI>       case HP.PieceType of
DI>         ptHtmlTag:
DI>           begin
DI>             if HP.HtmlTag.Count > 1 then
DI>               HP.HtmlTag.DeleteAt(1);
DI>             HW.WriteCurrentHtmlTag;
DI>           end;
DI>       end;

DI>     WriteLn(HW.Writer.DataToStrA);

DI>   finally
DI>     HW.Free;
DI>     HP.Free;
DI>   end;

DI>   WriteLn;
DI>   WriteLn('Done - Press ENTER to Exit');
DI>   ReadLn;
DI> end.
DI> _______________________________________________
DI> Delphi Inspiration mailing list
DI> yunqa@xxxxxxxxxxxxx
DI> //www.freelists.org/list/yunqa
_______________________________________________ Delphi Inspiration mailing list yunqa@xxxxxxxxxxxxx //www.freelists.org/list/yunqa

Other related posts: