It’s possible to read data from an external file (text or XML, it doesn’t matter) and access the contents from JavaScript. For security reasons, you’ll have to use HEScript functions.
Here is the code example (insert it in UserMain):
uses Classes; // Add this to the top of the script
function ReadXMLFile(Filename: String): String;
var
T: TStringList;
S: String;
begin
T := TStringList.Create;
try
// Loads the XML file in the same path as the ebook EXE file.
EbookPath := GetGlobalVar("HEPublicationPath", "");
S := EbookPath + Filename;
T.LoadFromFile(S);
// Gets the contents.
Result := T.Text;
finally
T.Free;
end;
end;
Now you can call this function from JavaScript. Suppose that the XML file is named mydata.xml and is available in the same folder as the EXE file:
var s = window.external.GetHEScriptCom('usermain.ReadXMLFile|mydata.xml', 'none');
alert(s);
Then your s variable contains the contents of the XML file.