I use TXMLDocument to manipulate XML. When I load XML that contains accented
characters (like é), I can't set the Active property to True. Is there a way
to change that? I can't see a property in TXMLDocument that seems to address
this issue. Does it have to do with Windows regional settings, or the MS
parser?
Thank you,
--
Alain Quesnel
alains...@logiquel.com
Thank you,
--
Alain Quesnel
alains...@logiquel.com
"Alain Quesnel" <alains...@logiquel.com> wrote in message
news:4742...@newsgroups.borland.com...
The SOAP runtime uses the TXMLDocument and we load XML data with accented
characters in our test suites regularly (more on that below). I need a
little more information to investigate this issue but I suspect that it will
probably boil down to whether the file you're loading is encoded and how you
are loading it. By default the underlying XMLDom used by TXMLDocument will
utf-8 encode and assume utf-8 encoding. So the XML file may skip the
encoding if it uses that default but best would be to be explicit.
If the XML file you are using is encoded some other way. Say it's utf-16
encoded, then as long as it contains the proper marker, TXMLDocument will
handle it correctly.
You can try all of this yourself just to identify whether the problem lies.
For example, if you create an XML file using something along the lines of:
XMLDocument1.Active := True;
XMLDocument1.Encoding := 'utf-16';
Node := XMLDocument1.AddChild('data', 'ns:test');
Node.SetAttributeNS('value', 'ns:test', 'Le châtiment: la fenêtre fermée a
clef.');
XMLDocument1.SaveToFile('test.xml');
You should be able to load that file using some code like this:
XMLDocument1.LoadFromFile('test.xml');
XMLDocument1.Active := True;
If you leave out the explicit setting of the encoding above, the file is
utf-8 encoded. Of course, it would be best to explicitly say so as it will
include the encoding in the XML file as in:
<?xml version="1.0" encoding="utf-16"?>
<data xmlns="ns:test" value="Le châtiment: la fenêtre fermée a clef."/>
(You can't tell but the file created above contains a BOM marker and is
utf-16 encoded).
If the XML files you are using don't contain encoding information, you may
need to load the files via TXMLDocument.LoadFromStream as it allows you to
specify the encoding.
Let me know if the above does not help. It would be useful to know which API
you're using to load the file (LoadFromFile vs. LoadFromStream), whether the
files contain encoding information and how they are encoded.
Cheers,
Bruneau.
PS: The following is from the SOAP Unit Tests. It is a simple routine that
returns a string that we send to .NET and Axis services we have setup to
echo back data. As you can see the strings contain accented characters:
function RandString: String;
const
LF = #10;
TB = #8;
Tartufe = 'Le châtiment de Tartufe' + LF
+
'Tisonnant, tisonnant son coeur amoureux...' {+
LF};
Cloche = 'Dans chaque église, il y a toujours quelque chose qui cloche';
Pater = 'Notre Père qui êtes aux cieux' + LF
+
'Restez-y';
Jours = 'Bien sûr, des fois, j''ai pensé mettre fin à mes jours,' + LF
+
'mais je ne savais jamais par lequel commencer';
Bain_De_Soleil = 'La salle de bains est fermée a clef.' + LF +
'Le soleil entre par la fenêtre' + LF +
'Et il se baigne dans la baignoire' + LF +
'Et il se frotte avec le savon' + LF +
'Et le savon pleure' + LF +
'Il a du soleil dans l''oeil!';
Algo_me_dicen = 'Algo me dicen tus ojos;' + LF +
'Mas lo que dicen no sé.' + LF +
'Entre misterio y sonrojos,' + LF +
'Algo me dicen tus ojos.' + LF +
'¿Vibran desdenes y enojos,' + LF +
'O hablan de amor y de fe?' + LF +
'Algo me dicen tus ojos;' + LF +
'Mas lo que dicen no sé';
{ Array of quotes }
Quotes: array[0..5] of string = (Tartufe, Cloche, Pater, Jours,
Bain_De_Soleil,
Algo_me_dicen);
if frmGPXdlg.Execute then
begin
XMLDocument1.Encoding := 'utf-16'; //I added this line like you
suggested
XMLDocument1.XML.Assign(frmGPXdlg.Memo1.Lines);
end;
XMLDocument1.Active := True;
It doesn't work. I get an "Invalid character at line 10" error. Line 10
contains the first accented character.
I need to be able to paste the XML into a TMemo. So far, the workaround I
have found is to paste the XML into NotePad, save it as a Unicode file, and
then do this:
if OpenDialog1.Execute then
begin
XMLDocument1.LoadFromFile(OpenDialog1.FileName);
end;
I posted a sample (on the attachments NG) of the XML I'm trying to paste
into the TMemo.
Merci,
Alain Quesnel
alains...@logiquel.com
"Jean-Marie Babet" <bba...@borland.com> wrote in message
news:47433f25$1...@newsgroups.borland.com...