如何控制旧应用程序的空值元素? [英] How to control empty value element for the old application?
本文介绍了如何控制旧应用程序的空值元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为最大客户的应用程序是很老的旧。
如果元素为空值,该应用程序只接受空标记:
< abc>< / abc>
我们的程序是使用XmlDocument对象用C#编写,它将空值写为:
< abc />
我可以强制XmlDocument类将空标记写为:
< abc>< / abc>
?
As the largest client's application is very old old old.
That application only accept the empty tag if the element is empty value:
<abc></abc>
Our program is written in C# using XmlDocument object, it write the empty value as:
<abc/>
Can I force the XmlDocument class write the empty tag as:
<abc></abc>
?
推荐答案
不确定是否有更简单的方法这样做,但你可以像这样实现一个自定义的XmlWriter:
No sure if there is an easier way to do this, but you can implement a customized XmlWriter like this:
class MyXmlWriter : XmlTextWriter
{
public MyXmlWriter(TextWriter w) : base(w) { }
public override void WriteEndElement()
{
base.WriteFullEndElement();
}
}
然后使用此编写器保存xml文件:
Then use this writer to save the xml file:
XmlWriter xw = new MyXmlWriter(new StreamWriter("test.xml"));
XmlDocument doc = new XmlDocument();
doc.LoadXml("<a><b/></a>");
doc.Save(xw);
doc = null;
xw.Close();
希望有所帮助。
Hope it helps.
这篇关于如何控制旧应用程序的空值元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文