2016-09-15 53 views
-1

下面是示例XMLSSIS腳本任務 - 有問題,而解析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>

我試圖讓服務器ID和姓名。這裏是我的代碼。但它沒有任何回報。

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

+0

下不加評論投票?自己解釋一下。 – sam

回答

0

這工作。

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))