Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-02

ReadXMLFile() fails reading a xml file

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Part of creating a new cross-platform installer application, I'm trying to read an XML file that contains UTF-8 characters, but I get the following error. Unicode support is very important, because the setup program must support multiple languages. Does this mean the XML implementation in FPC doesn't support Unicode enabled XML at all? :-(

  // that reads the xml file
  ReadXMLFile(doc, './setup.xml');   //  <<-- Fails on this line!
  if not Assigned(doc) then
    exit;

---------------------------------------------
$ ./setup_gui
DEBUG: TMainForm.FormShow >>
DEBUG: TMainForm.PopulateInstallOptions >>
An unhandled exception occurred at $000000000050E277 : EXMLReadError : In 'file:./setup.xml' (line 23 pos 20): Invalid character in input stream
$000000000050E277 line 1298 of src/xmlread.pp
$000000000050E12B line 1270 of src/xmlread.pp
$000000000050DF6E line 1252 of src/xmlread.pp
$00000000005161F4 line 3735 of src/xmlread.pp
$0000000000516361 line 3754 of src/xmlread.pp
$000000000046847B line 185 of frm_main.pas
$0000000000467DEE line 66 of frm_main.pas
$00000000004679DB line 350 of ../../gui/fpg_form.pas $00000000004676D8 line 287 of ../../gui/fpg_form.pas $000000000041D1CE line 22 of setup_gui.lpr
$000000000041D216 line 30 of setup_gui.lpr
---------------------------------------------

Here is a snippet of the XML file I'm trying to read -------------[ setup.xml ]--------------------
<?xml version="1.0" standalone="yes"?>
<install product="SC3U" desc="SimCity 3000 Unlimited" version="2.0"> <readme>
README
</readme>
<readme lang="fr">
README.fr
</readme>
<readme lang="de">
README.de
</readme>
<readme lang="es">
README.es
</readme>
<readme lang="sv">
README.sv
</readme>
<option install="true" required="true">
Base Install
<lang lang="fr">Installation de base</lang>
<lang lang="sv">Basinstallation</lang>
<lang lang="it">Installazione Minima</lang>
<lang lang="es">Básica Instalación</lang>
<lang lang="de">Basisinstallation</lang>
<lang lang="nl">Basis-installatie</lang>
<help>Required for play</help>
<help lang="fr">Requis pour jouer</help>
<help lang="sv">Filer som behövs för att spela</help> <help lang="it">Richieste Software</help>
<help lang="es">Requerido para el juego</help>
<help lang="de">Zum Spielen benötigt</help>
<help lang="nl">Vereist voor het spel</help>
...
----------------------------------------------

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 7 lines
Hi, Part of creating a new cross-platform installer application, I'm trying to read an XML file that contains UTF-8 characters, but I get the following error. Unicode support is very important, because the setup program must support multiple languages. Does this mean the XML implementation in FPC doesn't support Unicode enabled XML at all? :-(

It does, but you must specify the codepage in the XML header of the file.

<?xml version="1.0" encoding="utf-8"?>

And you must of course make sure the contents match the header :-)

Michael.

Show quoted text 78 lines
// that reads the xml file ReadXMLFile(doc, './setup.xml'); // <<-- Fails on this line! if not Assigned(doc) then exit; --------------------------------------------- $ ./setup_gui DEBUG: TMainForm.FormShow >> DEBUG: TMainForm.PopulateInstallOptions >> An unhandled exception occurred at $000000000050E277 : EXMLReadError : In 'file:./setup.xml' (line 23 pos 20): Invalid character in input stream $000000000050E277 line 1298 of src/xmlread.pp $000000000050E12B line 1270 of src/xmlread.pp $000000000050DF6E line 1252 of src/xmlread.pp $00000000005161F4 line 3735 of src/xmlread.pp $0000000000516361 line 3754 of src/xmlread.pp $000000000046847B line 185 of frm_main.pas $0000000000467DEE line 66 of frm_main.pas $00000000004679DB line 350 of ../../gui/fpg_form.pas $00000000004676D8 line 287 of ../../gui/fpg_form.pas $000000000041D1CE line 22 of setup_gui.lpr $000000000041D216 line 30 of setup_gui.lpr --------------------------------------------- Here is a snippet of the XML file I'm trying to read -------------[ setup.xml ]-------------------- <?xml version="1.0" standalone="yes"?> <install product="SC3U" desc="SimCity 3000 Unlimited" version="2.0"> <readme> README </readme> <readme lang="fr"> README.fr </readme> <readme lang="de"> README.de </readme> <readme lang="es"> README.es </readme> <readme lang="sv"> README.sv </readme> <option install="true" required="true"> Base Install <lang lang="fr">Installation de base</lang> <lang lang="sv">Basinstallation</lang> <lang lang="it">Installazione Minima</lang> <lang lang="es">Básica Instalación</lang> <lang lang="de">Basisinstallation</lang> <lang lang="nl">Basis-installatie</lang> <help>Required for play</help> <help lang="fr">Requis pour jouer</help> <help lang="sv">Filer som behövs för att spela</help> <help lang="it">Richieste Software</help> <help lang="es">Requerido para el juego</help> <help lang="de">Zum Spielen benötigt</help> <help lang="nl">Vereist voor het spel</help> ... ---------------------------------------------- Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
<?xml version="1.0" encoding="utf-8"?> And you must of course make sure the contents match the header :-)

Missing encoding and wrong content encoding was my problem. Oops! :) Thanks for the help, it's working now.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Lee Jenkins
to Michael Van Canneyt: It does, but you must specify the codepage in the XML header of the file. <?xml…
Michael Van Canneyt wrote 22 lines
On Tue, 2 Feb 2010, Graeme Geldenhuys wrote: > Hi, > > Part of creating a new cross-platform installer application, I'm > trying to > read an XML file that contains UTF-8 characters, but I get the following > error. Unicode support is very important, because the setup program must > support multiple languages. Does this mean the XML implementation in FPC > doesn't support Unicode enabled XML at all? :-( It does, but you must specify the codepage in the XML header of the file. <?xml version="1.0" encoding="utf-8"?> And you must of course make sure the contents match the header :-) Michael. > >

Isn't it supposed to assume utf-8 if no encoding processing instruction is present in the XML doc? I thought I read that somewhere...

Warm Regards, Lee
cobines
to Lee Jenkins

2010/2/2 Lee Jenkins :

Isn't it supposed to assume utf-8 if no encoding processing instruction is present in the XML doc?  I thought I read that somewhere...

It is supposed to look at "encoding" value, then BOM and if both are not present assume UTF-8.

cobines
Graeme Geldenhuys
to cobines
cobines wrote
It is supposed to look at "encoding" value, then BOM and if both are not present assume UTF-8.

That did not work for me, hence this message thread.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/