使用 XmlSerializer 设置 xml 标头 [英] Set xml header with XmlSerializer
本文介绍了使用 XmlSerializer 设置 xml 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 xml 看起来像那样...
My xml looks like that...
我有这个固定的标题,我需要附加到我正在编写的任何 xml 文件中,我该怎么做?
I have this fixed header I need to append to any xml file I am writing, an idea how do I do that?
**<?xml version="1.0"?>
<!DOCTYPE profile SYSTEM "criteria_profile.dtd">**
<profile type="INTERC" id="6 " description="MushonTest" state="" lastchuser="MUSHON" lastchtmstmp="20130903132018 " createuser="MUSHON">
<root>
<node type="A">
<item description="crite3">
<field>AUTHCKMAN<criterion sign="I" opt="EQ" low="cl" high=""/>
</field>
<field>JOBCLASS<criterion sign="I" opt="EQ" low="clas" high=""/>
</field>
<field>JOBNAME<criterion sign="I" opt="EQ" low="nam" high=""/>
</field>
<field>SDLUNAME<criterion sign="I" opt="EQ" low="creat" high=""/>
</field>
</item>
推荐答案
你只能通过 XmlWriter
做到这一点——不能直接作为 XmlSerializer
API 的一部分;但是你仍然可以在这里使用 XmlSerializer
,例如:
You can only do that via XmlWriter
- not directly as part of the XmlSerializer
API; but you can still use XmlSerializer
here, for example:
var ser = new XmlSerializer(typeof(Foo));
using (var xw = XmlWriter.Create({any output device here}))
{
xw.WriteDocType("profile", null, "criteria_profile.dtd", null);
ser.Serialize(xw, new Foo());
}
产生:
<?xml version="1.0"?><!DOCTYPE profile SYSTEM "criteria_profile.dtd"><Foo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
这篇关于使用 XmlSerializer 设置 xml 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文