I want XDocument
输出 XML 序言(例如“<?xml version="1.0" encoding="UTF-8"?>
") 大写。
这是我目前正在做的事情,但这似乎不起作用:
XDocument doc = new XDocument
(
new XDeclaration("1.0", "UTF-8",""),
bla bla bla);
doc.Save(@"Z:\test.xml");
)
此代码不起作用,它以小写形式出现。执行此操作时,不应更改标识和格式。
任何帮助将不胜感激。谢谢。
*EDIT:*这个问题仍然悬而未决,是否有更多的想法来解决这个问题。
XDocument xdoc = new XDocument();
.... // do your stuff here
string finalDoc = xdoc.ToString();
string header = finalDoc.Substring(0,finalDoc.IndexOf("?>") + 2); // end of header tag
finalDoc = finalDoc.Replace(header, header.ToUpper()); // replace header with the uppercase version
.... // do stuff with the xml with the upper case header
EDIT:
哦,你只想要 UTF-8 大写?
那么这样更正确:
XDocument xdoc = new XDocument();
.... // do your stuff here
string finalDoc = xdoc.ToString();
string header = finalDoc.Substring(0,finalDoc.IndexOf("?>") + 2); // end of header tag
string encoding = header.Substring(header.IndexOf("encoding=") + 10);
encoding = encoding.Substring(0,encoding.IndexOf("\""); // only get encoding content
// replace encoding with the uppercase version in header, then replace old header with new one.
finalDoc = finalDoc.Replace(header, header.Replace(encoding, encoding.ToUpper()));
.... // do stuff with the xml with the upper case header
这只会手动将编码中的内容替换为大写。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)