我正在尝试修改RDL文件中的connectionString,该文件动态地包含xml节点。但我只能使用/
检索根我无法检索任何其他节点,例如当我尝试检索connectString时它出现为null。
XmlDocument xml = new XmlDocument();
xml.Load(selectedFiles[0].ToString());
var connectionString = xml.SelectSingleNode("/");
RDL文件的xml:
<?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 :(得分:1)
您需要执行Xpath查询以获取连接字符串。它应该是这样的:
/报表/数据源[@名称= “DataSource1”] / ConnectionProperties中/ ConnectString中
但要注意正确处理命名空间。
参见这篇文章:
http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C