使用 C# WriteDocType() 生成符合 Apple 属性列表的 XML
我正在尝试生成一个 XmlDocument
,它具有 Apple 属性列表 (P-List) 格式中指定的 DocType,它应该如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
我目前拥有的代码如下所示
using (XmlTextWriter filenameXMLWriter = new XmlTextWriter(ms, null))
{
filenameXMLWriter.Formatting = Formatting.Indented;
filenameXMLWriter.WriteStartDocument();
filenameXMLWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
filenameXMLWriter.WriteStartElement("plist");
filenameXMLWriter.WriteAttributeString("version", "1.0");
..
..
}
: DocType
永远不会被写入文档(或者至少它永远不会出现在输出中)。我只是明白:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
如果有任何帮助,我将不胜感激。
I'm trying to produce an XmlDocument
which has a DocType as specified in Apple's Property List (P-List) format, which should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
The code I have at the moment looks like this:
using (XmlTextWriter filenameXMLWriter = new XmlTextWriter(ms, null))
{
filenameXMLWriter.Formatting = Formatting.Indented;
filenameXMLWriter.WriteStartDocument();
filenameXMLWriter.WriteDocType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
filenameXMLWriter.WriteStartElement("plist");
filenameXMLWriter.WriteAttributeString("version", "1.0");
..
..
}
The DocType
never gets written to the document (or at least it never appears in the output). I just get this:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
I'd be grateful for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了您的代码,并将输出内存流更改为文件路径,并在运行代码后检查输出文件,并且 DocType 已正确写入其中。
您可以尝试输出到代码中的文件以查看是否是 WriteDocType 行或内存流的问题?
此致,
路易斯·R
I tried your code and changed the output Memory Stream to a file path and checked the output file after running the code and the DocType was written to it correctly.
Can you try outputting to a file in your code to see if it's a problem with the WriteDocType line or the Memory Stream?
Regards,
Louis R