【问题标题】:SSIS script task - Having issue while parsing xmlSSIS 脚本任务 - 解析 xml 时出现问题
【发布时间】:2016-09-15 19:28:41
【问题描述】:

这里是示例 xml

<?xml version="1.0" encoding="utf-16"?>
<ServerInfoArrayResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Result xmlns="http://www.smartertools.com/smarterstats/ServerAdmin.asmx">true</Result>
  <ResultCode xmlns="http://www.smartertools.com/smarterstats/ServerAdmin.asmx">1</ResultCode>
  <Message xmlns="http://www.smartertools.com/smarterstats/ServerAdmin.asmx" />
  <Servers xmlns="http://www.smartertools.com/smarterstats/ServerAdmin.asmx">
    <ServerInfo>
      <ServerID>1234</ServerID>      
      <Name>server1234</Name>
    </ServerInfo>
</Servers>
</ServerInfoArrayResult>

我正在尝试获取 ServerID 和名称。这是我的代码。但它没有返回任何东西。

ar nsmgr = new XmlNamespaceManager(xDoc.NameTable);
    nsmgr.AddNamespace("a", "http://www.w3.org/2001/XMLSchema-instance");
    

    foreach (XmlNode xNode in xDoc.SelectNodes("/Servers/ServerInfo"))
    {
        //Add new row to the output buffer for each employee node in the XML file
        this.ServerInfoBuffer.AddRow();

        //Assign values to the columns.

        //Read the 1st attribute of the node Employee
        this.ServerInfoBuffer.ServerID = xNode.ChildNodes[0].InnerText;
        
        this.ServerInfoBuffer.ServerName = xNode.ChildNodes[1].InnerText;
        
    }
}

【问题讨论】:

  • 投反对票而不发表评论?解释你自己。

标签: xml ssis script-task


【解决方案1】:

这行得通。

 XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
        nsmgr.AddNamespace("a", "http://www.smartertools.com/smarterstats/ServerAdmin.asmx");

        foreach (XmlNode xNode in xDoc.SelectNodes("//ServerInfoArrayResult/a:Servers/a:ServerInfo", nsmgr))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多