We have such a text file with such content.
Package.ConnectionManagers [xxx] | {XXX-XXXX-XXXX-XXXX-XXXX} | Data Source = YYY; User ID = fjfjf; | ACS Available Moths.dts
We have this XML file
<?xml version="1.0" encoding="utf-8"?> <connections> <connection refId="PackageId..." connectionManagerID="conManagerId..." connectionManagerRefId="conManRefId..." description="des..." name="OleDbConnection..." /> </connections>
After we have this file
<?xml version="1.0" encoding="utf-8"?> <connections> <connection refId="PackageId..." connectionManagerID="{XXX-XXXX-XXXX-XXXX-XXXX}" connectionManagerRefId="Package.ConnectionManagers[xxx]" description="des..." name="OleDbConnection..." /> </connections>
Here is the complete program code, you can experiment
class Program { static void Main(string[] args) { string xmlFile = @"D:\cons.xml"; string txtFile = @"D:\cons.txt"; //MakeXML(xmlFile); ChangeConnectionAttributes(xmlFile, txtFile); } private static void MakeXML(string xmlFile) { XDocument doc = new XDocument(); XElement elm = new XElement("connections", new XElement("connection", new XAttribute("refId", "PackageId..."), new XAttribute("connectionManagerID", "conManagerId..."), new XAttribute("connectionManagerRefId", "conManRefId..."), new XAttribute("description", "des..."), new XAttribute("name", "OleDbConnection..."))); doc.Add(elm); doc.Save(xmlFile); } private static void ChangeConnectionAttributes(string xmlFile, string txtFile) { var strs = File .ReadAllText(txtFile) .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); XDocument doc = XDocument.Load(xmlFile); var c1 = doc.Descendants("connection") .First() .Attributes() .First(a => a.Name == "connectionManagerID").Value = strs[1]; var c2 = doc.Descendants("connection") .First() .Attributes() .First(a => a.Name == "connectionManagerRefId").Value = strs[0]; doc.Save(xmlFile); } }
А[i] == B[i]preliminary in And and B having read files. - nick_n_a