使用 C# WriteDocType() 生成符合 Apple 属性列表的 XML

发布于 2024-09-02 10:31:27 字数 994 浏览 6 评论 0原文

我正在尝试生成一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2024-09-09 10:31:27

我尝试了您的代码,并将输出内存流更改为文件路径,并在运行代码后检查输出文件,并且 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文