使用Delphi7 TClientDataSet:是否可以将其保存为缩进格式的XML内容 [英] Using Delphi7 TClientDataSet: is it possible to have it save it's XML contents in an indented format
问题描述
我正在使用Delphi7 ClientDataSet读取和写入我的一些数据的xml文件。
I am using Delphi7 ClientDataSet to read and write xml files for some of my data.
Howerver,当我想在程序外浏览(双击xml在Windows资源管理器中)我得到'在文本内容中找到一个无效的字符。处理资源时出错 - 即使数据在Delphi内读取和写入也不错。
Howerver, when I want to browse this outside the program (double clicking the xml in Windows Explorer) I get the 'An invalid character was found in text content. Error processing resource' - even although the data reads and writes fine from within Delphi.
有没有办法强制TClientDataSet以缩进的方式写入内容一行?
Is there a way to force TClientDataSet to write it's contents in an indented way in stead in one line ?
这样我就可以轻松地将其打开到一个文本编辑器中,找出什么角色将触发上述错误。
That way I could easily open it into a text editor and find what character will trigger the above error.
无论如何,我发现,使用CR / LF和缩进的XML文件可以更清晰。
Anyway: I find it much more clearer for an XML file to be written with CR/LF and indents anyway.
提前Thx。
推荐答案
这是因为正确的编码(如<?xml version =1.0encoding =UTF-8 ?>
)没有在您的输出文件中指定,但它包含一些具有不兼容编码的字符。
It's because the proper encoding (like <?xml version="1.0" encoding="UTF-8"?>
) has not be specified in your output file, yet it contains some characters with an incompatible encoding.
As RRUZ提到的,将 TDataPacketFormat
显式指定为 dfXMLUTF8
在编写文件时肯定会解决无效字符错误,因为它将首先编写编码标签:
<?xml version =1.0 encoding =UTF-8standalone =yes?> < DATAPACKET Version =2.0> [...]
您还可以在已存在的文件的文件开头手动添加编码。
As RRUZ mentioned, specifying explicitly the TDataPacketFormat
as dfXMLUTF8
when writing the file will most certainly solve the 'Invalid Character' error, as it will write the encoding tag first:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DATAPACKET Version="2.0">[...]
You can also add the encoding manually at the beginning of the file for already existing files.
对于可读格式化,一些读者可以读取原始的一行内容,并为您进行格式化(像FireFox或Internet Exporer这样的浏览器,以及XML编辑器,如 XMLNotePad )
As for the readable formatting, some readers can read the raw one-liner and do the formatting for you (browsers like FireFox or Internet Exporer, and XML editors like XMLNotePad)
这篇关于使用Delphi7 TClientDataSet:是否可以将其保存为缩进格式的XML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!