使用SSIS脚本组件提取XML数据

时间:2017-11-23 22:30:34

标签: sql-server xml ssis

我正在尝试使用脚本组件(源)提取xml数据,我的xml包含多个名称空间,因此我创建了一个带有名称空间去除方法的类。但我得到一个错误“路径中的非法字符”我不确定,代码的哪一部分是不正确的,有人请给我一个解决方案

{
public override void CreateNewOutputRows()
    {
        /*
          Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
          For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
        */

        string filepath =@"D:\test\QuoteStop\StopQuoteResponseLog.1.xml";
        string fileContent = new StreamReader(filepath).ReadToEnd();
        XmlDocument doc = new XmlDocument();
        doc.Load(fileContent);
       // MessageBox.Show(fileContent);
        NsRemove rm = new NsRemove();
        rm.stripDocumentNamespace(doc);
        XmlNodeList xnl = doc.GetElementsByTagName("OrderResponseLog");

        foreach (XmlNode xn in xnl)
        {

            Output0Buffer.AddRow();
            if (xn["operationType"] != null) 
            {
                Output0Buffer.operationType = xn["operationType"].InnerText;
            }
            if (xn["quoteNumber"] != null) 
            {
                Output0Buffer.quoteNumber = xn["quoteNumber"].InnerText;
            }



        }

    }

}

public class NsRemove
{
    public XmlDocument stripDocumentNamespace(XmlDocument oldDom)
    {
        // Remove all xmlns:* instances from the passed XmlDocument
        // to simplify our xpath expressions.
        XmlDocument newDom = new XmlDocument();
        newDom.LoadXml(System.Text.RegularExpressions.Regex.Replace(
        oldDom.OuterXml, @"(xmlns:?[^=]*=[""][^""]*[""])", "",
        System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline)
        );
        return newDom;
    }
}

sample xml

0 个答案:

没有答案