tags:

views:

62

answers:

2

How I can fix this?

  Tdm = class(TDataModule)
  HTTP: TIdHTTP;
  XMLDoc: TXMLDocument;
  ...
  var sStory: String;
  ...
  sStory:= GetHTTP('http://localhost/MultiPlay_PHP/contentlesson.php');
  begin
  xmlDoc.XML.Text := sStory;
  xmlDoc.Active :=true;

  StartItemNode := XMLDoc.DocumentElement.ChildNodes.First;
  ANode := StartItemNode;

The error starts on the xmlDoc.Active code.

<?xml version="1.0" encoding="UTF-8" ?> 
- <WORDSET>
- <WORD NUMBER="1">
  <ENGLISH>beat</ENGLISH> 
  <KOREAN>두드리다</KOREAN> 
  </WORD>

Project.exe raised exception class EDOMParseError with message 'An invalid character was found in text content. But when I remove the Korean characters from the XML, then the code is okay.

+1  A: 

I suspect that your webserver is not returning the content UTF-8 encoded. You can try to change the encoding of the result by changing the declaration of sStory: String to sStory : UTF8string

Using the following code block I can not duplicate the problem.

var
 sStory : Utf8String;
begin
 sStory := '<?xml version="1.0" encoding="UTF-8" ?>' +
           '<WORDSET>'  +
           '<WORD NUMBER="1">'  +
           '<ENGLISH>beat</ENGLISH>'  +
           '<KOREAN>두드리다</KOREAN>'  +
           '</WORD>'  +
           '</WORDSET>';
 xmlDoc.XML.Text := sStory;
 xmlDoc.Active := true;
end;
Robert Love
I changed that GetHTTP function's return type to Utf8String (and sstory's type too) but I still had the error.But thanks for answering anyway.
Dian
+1  A: 

I see you use Indy's http component. When you get an URL you have to provide a stream (which you probably do in your GetHTTP method). When that stream contains the xml and nothing else, use the stream directly with the LoadFromStream method of your TXMLDocument. TXMLDocument will determine the encoding so it saves you from fooling around with strings and encodings.

Ofcourse, for al this to work contentlesson.php has to return proper XML (as commented by Robert Love). If that part you posted is exactly what you got from that page, then it is not your fault when you get errors.

The_Fox
It worked! Thanks!
Dian