我需要在将XML传递到存储过程时删除XML声明 因为如果我们包含XML声明,它将给出错误
<?xml version="1.0" encoding="SHIFT-JIS" standalone="yes"?>
我google了很多但仍然无法解决我的上述问题。请帮忙!
(0x80131904) XML line 1 character 9 . cannot be switch ...
答案 0 :(得分:0)
发现它对我有用:
string xml = File.ReadAllText(xmlfilePath, Encoding.GetEncoding("SHIFT_JIS"));
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
if (doc.FirstChild.NodeType == XmlNodeType.XmlDeclaration)
doc.RemoveChild(doc.FirstChild);
xml = GetXMLAsString(doc);
public string GetXMLAsString(XmlDocument myxml)
{
StringWriter sw = new StringWriter();
XmlTextWriter tx = new XmlTextWriter(sw);
myxml.WriteTo(tx);
string str = sw.ToString();//
return str;
}