Answer the question
In order to leave comments, you need to log in
How to load XML content in ListBox?
There is an xml document in the program resources.
When I try to load a list from it into a ListBox, I get the error "Declared encoding does not match byte order mark".
The error is only when running an android project. Under Windows everything works fine.
<?xml version="1.0" encoding="utf-8"?>
<resourсes>
<question>
<item>Данные1 | Описание</item>
<item>Данные2 | Описание</item>
</question>
</resourсes>
procedure Form1.ListBoxItem1Click(Sender: TObject);
var
Stream: TResourceStream;
RootNode: IXMLNode;
i: Integer;
begin
Stream:=TResourceStream.Create(hInstance, 'xmldoc', RT_RCDATA);
mldocument1.xml.LoadFromStream(Stream);
xmldocument1.Active:=true;
xmldocument1.Encoding:='UTF-8';
RootNode := XMLDocument1.DocumentElement;
for i := 0 to RootNode.ChildNodes['question'].ChildNodes.Count - 1 do
begin
Listview1.Items.Add.Text:=(RootNode.ChildNodes['question'].ChildNodes[i].Text);
FreeAndNil(Stream);
end;
xmldocument1.Active:=false;
Stream.Free;
end;
Answer the question
In order to leave comments, you need to log in
The problem is not in the ListBox, but in the fact that the encodings do not match. The encoding specified in the file header and the actual encoding of the file. Windows implementation of xml probably silently swallows the inconsistency, as noted in the comments
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question