XML 转换后保留 DTD
我正在转换一个 XML 文档,但转换后我的 DTD 消失了,而且告诉 XML 版本的第一行也丢失了。
<?xml version="1.0"?>
我用来转换 XML 文件的代码是:
// Load the style sheet.
var xslt = new XslCompiledTransform();
xslt.Load("XSLTFile1.xslt");
// Create the writer.
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t",
ConformanceLevel = ConformanceLevel.Auto,
Encoding = Encoding.UTF8,
};
var mydoc = XDocument.Load("Doc1.xml");
var writer = XmlWriter.Create("Doc2.xml", settings);
// Execute the transform and output the results to a file.
if (writer != null)
{
xslt.Transform(mydoc.CreateReader(), writer);
writer.Close();
}
有什么想法吗?
I am transforming an XML document but after the transform my DTD goes away and also the first line which tells the XML version is missing.
<?xml version="1.0"?>
The code I am using to transform the XML file is:
// Load the style sheet.
var xslt = new XslCompiledTransform();
xslt.Load("XSLTFile1.xslt");
// Create the writer.
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t",
ConformanceLevel = ConformanceLevel.Auto,
Encoding = Encoding.UTF8,
};
var mydoc = XDocument.Load("Doc1.xml");
var writer = XmlWriter.Create("Doc2.xml", settings);
// Execute the transform and output the results to a file.
if (writer != null)
{
xslt.Transform(mydoc.CreateReader(), writer);
writer.Close();
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了保留 XML 声明,您需要在
XmlWriterSettings
中确保OmitXmlDeclaration
设置为false
:至于 DTD“ away” - 由于您正在转换文档,因此您应该向转换后的文档添加新的 DTD 声明。
如果没有
xsl
和xml
文件,就很难确定。您可以编辑您的问题并添加它们吗?In order to keep the XML declaration, you need to make sure in your
XmlWriterSettings
thatOmitXmlDeclaration
is set tofalse
:As for the DTD "going away" - since you are transforming the document, you should add a new DTD declaration to the transformed document.
Without the
xsl
andxml
files, it is difficult to tell for certain. Can you edit your question and add them?嘿,谢谢你的回复。我做到了
并且成功了。是的,我也有,
谢谢
hey thanks for the reply. I did
And it worked. Yes I also have
Thanks