Re: HTML Parser
From: eshipman (mr_delphi_developer_at_yahoo!!!.com)
Date: 10/19/04
- Next message: Gerard: "Re: HTML Parser"
- Previous message: Eugene Mayevski: "Re: HTML Parser"
- In reply to: Kees Vermeulen: "Re: HTML Parser"
- Next in thread: Gerard: "Re: HTML Parser"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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>
- Next message: Gerard: "Re: HTML Parser"
- Previous message: Eugene Mayevski: "Re: HTML Parser"
- In reply to: Kees Vermeulen: "Re: HTML Parser"
- Next in thread: Gerard: "Re: HTML Parser"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|