Please refer The code I have provided below.
****XMLDoc.Active := True;
XMLDoc.Options := [doNodeAutoCreate, doNodeAutoIndent];
XMLDoc.Version := '1.0';
XMLDoc.Encoding := 'utf-8';****
?xml version="1.0" encoding="UTF-8"? This is the expected result when I open the XML file. But it is not showing encoding="UTF-8" in the XML file. Because of which I think the degree symbol is not properly displayed in the XML file.(as it is not able to encode).
I changed UTF-8 to UTF-16,But when I tried to open the XML file it showed the error message like Switch from current encode to specified encode not supported. I guess there is some encoding problem in RAD Studio XE7 because for previous version ( Delphi XE5) it was working fine. Please give me some suggestions.
Below I am providing the sample code.
XMLDocument1:= TXMLDocument.create(nil);
XMLDocument1.Active := True;
XMLDocument1.Version :='1.0';
XMLDocument1.Encoding :='UTF-8';
XMLDocument2:= TXMLDocument.create(nil);
XMLDocument2.Active := True;
XMLDocument2.Version :='1.0';
XMLDocument2.Encoding :='UTF-8';
{ Add new child. This will become the document element.
If the document element already exists, then an exception is raised. }
//LNode := XMLDocument1.AddChild('Airbus');
LNode := XMLDocument1.CreateElement('TestElement', '101°F (38.33°C)');
XMLDocument1.DocumentElement := LNode;
{ Display document content. }
XMLDocument1.SaveToFile('c:\mk1.xml');
{if we take xmldocuments.xml.text method is not taking “Encoding=’UTF-8’}
XMLDocument2.LoadFromFile ('c:\mk1.xml');
**strsampletext:= XMLDocument2.XML.text; //Here I am not getting "Encoding='UTF-8". and the string "strsampletext" passed as a parameter**. If I write "strsampletext" into another XML file I can't view Degree Symbol correctly when I view in IE.
After loading the saved XML, the encoded UTF-8 is not taking.