Re: HTML Parser

From: eshipman (mr_delphi_developer_at_yahoo!!!.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 08:53:17 -0500

In article <4174d45d$1@newsgroups.borland.com>, info@kever.com says...
> Avatar,
>
> Thanks for your extensive reply, however some questions remain.
>
> What I'm trying to do is building a kind of document merge application.
> Users can create email-templates using Microsoft's HTML editor components
> and (therefore) these templates are stored as HTML files. Field elements are
> indicated using the following HTML tag:
>
> <span datafld="A Fieldname">Some Text</span>
>
> However, because my users are no computer experts, I am thinking about
> changing this to a simple: '<<A FieldName>>' (no tags, just plain text).
>
> Now I want to merge this HTML document with data either stored in a xml
> document or database. For this I load the HTML in a TWebBrowser control and
> then run through the document. Every '<span/>' tag is replaced by data taken
> from the database.
>
> I agree with you that XML/XSL would be great for document merging but I
> don't see how users having no knowledge of computers can create XSL
> documents with ease. That's why I chose HTML.
>
> Using TWebBrowser has some disadvantages:
> - The HTML document can only be accessed after it has been processed and
> this requires a visual control;
> - Sometimes replacing a tag with new data results in an empty document.
>
> I hope, after reading this info, you have additional tips for me on how to
> implement such an application.

Give this a try.

procedure WBChangeTag
  ( AWebBrowser: TWebBrowser
  ; ASearchAttribute: String
  ; ASearchAttributeValue: String
  ; AFieldText: String
  );
var
  LTextRange: IHTMLTxtRange;
  LElementColl: IHTMLElementCollection;
  LElement: IHTMLElement;
  LIndex: Integer;
  LAttribute: OleVariant;
begin
   if Assigned(AWebBrowser.Document) then
   begin
     LElementColl := (AWebBrowser.Document as IHTMLDocument2).all;
     for LIndex := 0 to LElementColl.length-1 do
     begin
       LElement := LElementColl.item(LIndex, EmptyParam) as
IHTMLElement;
       LAttribute := LElement.getAttribute(ASearchAttribute, 0);
       if Lattribute = ASearchAttributeValue then
       begin
         LElement.innerText := AFieldText;
       end;
     end;
   end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  WBChangeTag(WB, 'datafld', 'A Fieldname', 'My New Text');
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  WB.Navigate('c:\atest.html');
end;

HTML use in this test:

<html>
  <head>
    <title>Test page</title>
  </head>
  <body>
    <span datafld="A Fieldname">Some Text</span>
  </body>
</html>



Relevant Pages

  • Re: [FAQ] addslashes() and striplashes()
    ... How do I use addslashes() and stripslashes() when dealing with HTML ... Use addslasheswhen INSERTing or UPDATEing data into the database. ...
    (comp.lang.php)
  • Re: Virtual SBS server
    ... I have been posting in HTML since I became an MVP for SBS 5 years ago. ... With regard to Outlook over HTTP, it might be a bit faster since you don't have the VPN overhead to contend with. ... >>Depending on the database VPN may work, ... >desktop so making the server do all the work would be ...
    (microsoft.public.backoffice.smallbiz)
  • Re: following radio & hidden does not work..... help please.
    ... So you query the database for records and present the concatenated fname and lname for the user to choose from. ... This works the same with a radio button or a select statement. ... This is a HTML or PHP question! ...
    (alt.html)
  • Re: Problems with HTML Imports
    ... > fixes or workarounds, I sure would like to know. ... > When exporting data in html from one database that includes the "time" ... Why you are using HTML format to transfer data between databases? ...
    (comp.databases.ms-access)
  • Re: Photographs in British Naturism
    ... source code file, html, jsp, php or what ever), the only factor is ... not to the server if it's serving a html file, ... Currently, it's programmed to generate HTML pages from the text which operators have typed into the database through the admin interface. ...
    (uk.rec.naturist)