How to recover elements stored in an HTML hyperlink

Hi all
Complete beginner in xojo! (and programming too...)
From an HTMLViewer (used just to display an html hypertext), I would like to recover an element stored in the html code of an hyperlink, for example an image name or number to use that as a variable in my xojo project.
Maybe the question is simplistic.
Thank you for understanding!
Paolo from France

Welcome to Xojo.

Your problem is not a simple one. I do something similar and it’s rather fiddly to get data out of html.

Can you show or upload some of your html? What data do you want to get out?

To get data out of html I usually use regex - pattern matching. This describes a word pattern which usually looks like chicken scratch. It’s not possible to use a simple search because the html can be variable.

For instance, the following pattern matches an image in html:

<img.*src\s?=\s?""(.*)""(.*)>

The docs at https://documentation.xojo.com/api/text/regular_expressions/regex.html explain in more detail how to use regex.

Okay.
The hypertexts that I write are intended for students who, by clicking on the links, go to another window of the project containing an illustration of this link. Is the HTMLViewer is the most convenient for displaying styled text and active links?
Example: <a href://“1478.jpg”>A hyperlink.
Thanks Beatrix for your help.
I have a lot to learn!!!

If the hyperlinks are going to another Xojo window, and not another HTML document, you would need to capture it in the CancelLoad event.

on CancelLoad(URL As String) As Boolean
  select case URL
  case "1478.jpg"
    // do your thing to the other window
  end select
  return True  // cancel the loading of the URL
end CancelLoad

This code must be in a mousedown of HTMLviewer ?

It looks like LiveCode…(On End)

CancelLoad event of the HTMLViewer

image

In this case, HTMLViewer don’t loadpage (as styled html text) on opening…
Sorry

What operating system are you using?

MacOS Catalina

If you already have the HTML in a file, why dont you load it as text and do the string search from there?? :face_with_raised_eyebrow:

Everything is working fine for me (things we always want to hear when it doesn’t work for us). Check to ensure that the path is correct, folders named properly (check the case of the folder names just incase)

DIM f As FolderItem = SpecialFolder.ApplicationData.Child("ResCV2021").Child("Textes").Child("TxtMardi.html")
if (f = Nil) OR (not f.Exists) then MessageBox("No File")
me.LoadPage(f)

Try that code and see if there is a message box saying “No File”

Sorry, all seems to be correct.
Note: Selecting the CancelLoad as comment to deactivate the html file is loaded.

With the CancelLoad you would need to check for your base file and Return FALSE (to let the file load).

Thanks Ivan
In a text there are many occurences of the same word.
An hyperlink is unique in the file.

DIM result As Boolean = FALSE

select case URL
case "1478.html"
  result = TRUE
end select

Return result

Try this updated CancelLoad. It should allow your main page to load and then cancel loading when the URL is “1478.html”

OK Loading works fine now ; but nothing on clicking on the links…
Is this code correct for the html links ?:
merisier

In the CancelLoad event

DIM result As Boolean = TRUE

select case URL
case "http://1478.jpg/"
else
  result = FALSE
end select

Return result

You would do a Case statement for each link in your document. I’ve made a change to the select statement so that it will automatically not load the page, if the URL is handled by a case otherwise the URL will load, allowing your base HTML page to load, as well as any others you may want (without needing to handle them individually)