DelphiFan Magazine

Top Menu

Main Menu

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS

logo

DelphiFan Magazine

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS
  • How to add a server application written in UNIGUI to startup?

  • UniGUI Expiry Link Anonymizer

  • UniGUI Add CAPTCHA to the WEB project

  • UniGui. Unique hybrid of Delphi and JS

  • How to transform a blob field into string lines (varchar) in SQL Firebird?

CODE SAMPLESDELPHI
Home›CODE SAMPLES›How to extract text between HTML or XML tags?

How to extract text between HTML or XML tags?

By admin
January 7, 2021
590
0
Share:

There are certain types of data that we want to collect from HTML or XML,
for handling them, or better display.

There are ways to do this with TWebBrowser, but it forces us to have
to load the file in it and the manipulation is not
very easy.

But let’s say we have HTML or XML in a variable, or even
retrieving it through a Get with Indy (IdHTTP) with Delphi,
how can we do the data mining?

Fortunately there is a very simple function that will help us!

Let’s go to the source code:

 

function ExtractText(aText, OpenTag, CloseTag : String) : String;
{ Retorna o texto dentro de 2 tags (open & close Tag's) }
var
  iAux, kAux : Integer;
begin
  Result := '';
 
  if (Pos(CloseTag, aText) <> 0) and (Pos(OpenTag, aText) <> 0) then
  begin
    iAux := Pos(OpenTag, aText) + Length(OpenTag);
    kAux := Pos(CloseTag, aText);
    Result := Copy(aText, iAux, kAux-iAux);
  end;
end;

Example of use:

procedure TForm1.Button1Click(Sender: TObject);
const
  HTML =
  '<html>'+
  '<head>'+
  '<title>SHOW DELPHI</title>'+
  '</head>'+
  '<body>'+
  '<h1>Titulo 1</h1>'+
  '<h2>Titulo 2</h2>'+
  '</body>'+
  '</html>';
var
  variavelString : string;
begin
  variavelString := ExtractText(HTML,'<h1>', '</h1>');
  ShowMessage( variavelString );
end;

I hope it will be useful to everyone!

Tagsdelphiextract texthtmlparsexml
Previous Article

Internationalizing your application in Delphi

Next Article

How to add or remove hours from ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0
  • 0

admin

Related articles More from author

  • CODE SAMPLESTECH NEWS

    How to modify the maximum number of tcp connections on the windows server

    October 9, 2020
    By admin
  • DELPHI

    Where to download OpenSSL binaries?

    January 3, 2021
    By admin
  • CODE SAMPLESDELPHI

    Delphi UniDAC connects to the database via http protocol

    November 5, 2020
    By admin
  • CODE SAMPLESDELPHI

    Work with External program or Files in Delphi

    November 26, 2020
    By admin
  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi recognizes the battery level of an Android device

    December 10, 2020
    By admin
  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi Android permissions

    December 4, 2020
    By admin

Leave a reply Cancel reply

You may interested

  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi Firemonkey calls functions asynchronously in the main thread (delayed calls)

  • CODE SAMPLESDELPHI

    Customize the appearance of uniGUI TreeMenu

  • CODE SAMPLESDELPHI

    Socket error codes and possible problems

  • LATEST REVIEWS

  • TOP REVIEWS

Timeline

  • January 27, 2021

    How to add a server application written in UNIGUI to startup?

  • January 27, 2021

    UniGUI Expiry Link Anonymizer

  • January 26, 2021

    UniGUI Add CAPTCHA to the WEB project

  • January 26, 2021

    UniGui. Unique hybrid of Delphi and JS

  • January 13, 2021

    How to transform a blob field into string lines (varchar) in SQL Firebird?

Latest Comments

Find us on Facebook

Follow Us on Instagram

logo

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.

About us

  • 660 Pennsylvania Avenue Southeast #100 Washington, DC 20003
  • 0123456789
  • adsdelphi@gmail.com
  • Recent

  • Popular

  • Comments

  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • UniGUI Expiry Link Anonymizer

    By admin
    January 27, 2021
  • UniGUI Add CAPTCHA to the WEB project

    By admin
    January 26, 2021
  • UniGui. Unique hybrid of Delphi and JS

    By admin
    January 26, 2021
  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

    By admin
    August 13, 2020
  • Critical Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

    By admin
    September 4, 2020
  • Setting up the IDE for your first Android Application in Delphi

    By admin
    September 7, 2020

Follow us

Find us on Facebook

© Copyright Delphifan Forum. All rights reserved.