【问题标题】:Remove XML declaration while passing XML into a Stored Procedure将 XML 传递到存储过程时删除 XML 声明
【发布时间】:2017-12-12 09:12:00
【问题描述】:

在将 XML 传递到存储过程时,我需要删除 XML 声明 因为如果我们包含 XML 声明,它会报错

<?xml version="1.0" encoding="SHIFT-JIS" standalone="yes"?>

我搜索了很多,但仍然无法解决我的上述问题。请帮忙!

(0x80131904) XML line 1 character 9 . cannot be switch ...

【问题讨论】:

  • 您使用什么语言执行存储过程? SQL? C#?
  • SQL 服务器和 C#

标签: c# sql xml


【解决方案1】:

发现,它对我有用:

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;
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多