2013-05-08 104 views
0

我想修改一个RDL文件中的connectionString,它由动态的xml节点组成。但我只能使用/检索根,例如,当我尝试检索connectString时,我无法检索任何其他节点。如何动态修改RDl文件中的连接字符串?

XmlDocument xml = new XmlDocument(); 
xml.Load(selectedFiles[0].ToString()); 
var connectionString = xml.SelectSingleNode("/"); 

的XML的RDL文件:

<?xml version="1.0" encoding="utf-8"?> 
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"> 
    <AutoRefresh>0</AutoRefresh> 
    <DataSources> 
    <DataSource Name="DataSource1"> 
     <ConnectionProperties> 
     <DataProvider>SQL</DataProvider> 
     <ConnectString>Data Source=gbr-t-sql-001;Initial Catalog=Neptune2Dev</ConnectString> 
     <IntegratedSecurity>true</IntegratedSecurity> 
     </ConnectionProperties> 
     <rd:SecurityType>Integrated</rd:SecurityType> 
     <rd:DataSourceID>70fcaa8f-d76a-4919-a53c-ba313ca99926</rd:DataSourceID> 
    </DataSource> 
    </DataSources> 
    <DataSets> 
    <DataSet Name="DataSet1"> 
     <Query> 
     <DataSourceName>DataSource1</DataSourceName> 
     <QueryParameters> 
      <QueryParameter Name="@profileID"> 
      <Value>=Parameters!profileID.Value</Value> 
      </QueryParameter> 
     </QueryParameters> 
     <CommandType>StoredProcedure</CommandType> 
     <CommandText>Report_BylineSummary</CommandText> 

回答

0

您需要执行XPath查询来获取连接字符串。它应该是这样的:

/报告/数据源[@名称= “DataSource1”]/ConnectionProperties中/ CONNECTSTRING

但采取正确处理命名空间的照顾。

看到这篇文章:

http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C

+0

它配备了为空 VAR的connectionString = xml.SelectSingleNode( “/报告/数据源[@Name = \” DataSource1 \ “]/ConnectionProperties中/ ConnectString中” ); – Xerxes 2013-05-08 08:13:37

+0

正如我所说的,您必须正确处理名称空间才能使其正常工作。 http://support.microsoft.com/kb/316913 – Oscar 2013-05-08 08:18:23

相关问题