Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to call node directly from a node list and overwrite the inner text without looping from node list using c#. Currently I am able to do so by looping. Xml shown below and Code part also there in the code block

Xml is as below:

<?xml version="1.0"?>

<DTSConfiguration>


<DTSConfigurationHeading>

<DTSConfigurationFileInfo GeneratedDate="06/04/2018 11:06:33" GeneratedFromPackageID="{5A776659-3F33-4F34-A91A-D4BC80548271}" GeneratedFromPackageName="Package" GeneratedBy="CHN\Hasna.EK"/>

</DTSConfigurationHeading>


<Configuration ValueType="Boolean" Path="\Package.Connections[Flat File Connection Manager].Properties[AlwaysCheckForRowDelimiters]" ConfiguredType="Property">

<ConfiguredValue>-1</ConfiguredValue>

</Configuration>


-<Configuration ValueType="Int32" Path="\Package.Connections[Flat File Connection Manager].Properties[CodePage]" ConfiguredType="Property">

<ConfiguredValue>1252</ConfiguredValue>

</Configuration>


-<Configuration ValueType="Boolean" Path="\Package.Connections[Flat File Connection Manager].Properties[ColumnNamesInFirstDataRow]" ConfiguredType="Property">

<ConfiguredValue>-1</ConfiguredValue>

</Configuration>


-<Configuration ValueType="String" Path="\Package.Connections[Flat File Connection Manager].Properties[ConnectionString]" ConfiguredType="Property">

<ConfiguredValue>E:\SSIS\Test3\emp.txt</ConfiguredValue>

</Configuration>

</DTSConfiguration>


What I have tried:

Code as Below;
 string filename = "emp3.txt";

string dtConfigfilename = @"E:\SSIS\x.dtsConfig"; (Package Config File Configurable)
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(dtConfigfilename);
XmlNodeList nodeList = xmldoc.DocumentElement.ChildNodes;



foreach (XmlElement element in nodeList)
{
    if (element.Name == "Configuration")
    {
        if (element.Attributes["Path"].InnerText == "\\Package.Connections[Flat File Connection Manager].Properties[ConnectionString]")
        {
            element.ChildNodes[0].InnerText = @"E:\SSIS\Test2\" + filename; (Configurable file Store Folder)
            break;
        }
    }
}
xmldoc.Save(dtConfigfilename);
Posted
Updated 5-Apr-18 23:34pm
v2

1 solution

 
Share this answer
 
Comments
ranio 6-Apr-18 5:30am    
I tried the above method but cannot use as the configuration child node is there multiple times. i want to get the ConnectionString part with in a Configuration Child node in the XML Structure. I need to avoid the foreach loop currently being used.
Xml is as below:
<?xml version="1.0"?>

<dtsconfiguration>


<dtsconfigurationheading>

<DTSConfigurationFileInfo GeneratedDate="06/04/2018 11:06:33" GeneratedFromPackageID="{5A776659-3F33-4F34-A91A-D4BC80548271}" GeneratedFromPackageName="Package" GeneratedBy="CHN\Hasna.EK"/>




<Configuration ValueType="Boolean" Path="\Package.Connections[Flat File Connection Manager].Properties[AlwaysCheckForRowDelimiters]" ConfiguredType="Property">

<configuredvalue>-1




-<Configuration ValueType="Int32" Path="\Package.Connections[Flat File Connection Manager].Properties[CodePage]" ConfiguredType="Property">

<configuredvalue>1252




-<Configuration ValueType="Boolean" Path="\Package.Connections[Flat File Connection Manager].Properties[ColumnNamesInFirstDataRow]" ConfiguredType="Property">

<configuredvalue>-1




-<Configuration ValueType="String" Path="\Package.Connections[Flat File Connection Manager].Properties[ConnectionString]" ConfiguredType="Property">

<configuredvalue>E:\SSIS\Test3\emp.txt



</DTSConfiguration




doc.SelectSingleNode("/DTSConfiguration/DTSConfigurationheading/Configuration").InnerText = "test";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900