Skip to main content
 首页 » 编程设计

非 PUBLIC 的 C# CreateDocumentType

2024年08月06日31mfrbuaa

我想得到以下输出:

<?xml version="1.0" encoding="Windows-1252"?> 
<!DOCTYPE SUPRMRT SYSTEM "suprmrt.dtd"> 

我有以下代码:

XmlDocument doc = new XmlDocument(); 
XmlDocumentType docType = doc.CreateDocumentType("SUPRMRT", "SYSTEM", "suprmrt.dtd", null); 
doc.AppendChild(docType); 
doc.Save(Console.out); 

这会产生:

<?xml version="1.0" encoding="Windows-1252"?> 
<!DOCTYPE SUPRMRT PUBLIC "SYSTEM" "suprmrt.dtd"> 

所以我的问题是,我能否得到将 PUBLIC 替换为 SYSTEM 的结果?另外,如果我用 null 替换“SYSTEM”,我会得到一组空引号。我可以阻止这种情况发生吗?

请您参考如下方法:

这样写。

XmlDocumentType docType = doc.CreateDocumentType("SUPRMRT", null, "suprmrt.dtd", null); 

这是 MSDN Documentation

publicId

Type: System.String

The public identifier of the document type or null. You can specify a public URI and also a system identifier to identify the location of the external DTD subset.