ObjectType
OI
TYPE="private.value"
var rangefrom = Convert.ToInt32(startingRangetextbox.Text); var rangeto = Convert.ToInt32(RangeTotxtbx.Text); XDocument xdoc = XDocument.Load(FilePathtxtbx.Text); var dir = Path.GetDirectoryName(FilePathtxtbx.Text); var file = Path.GetFileName(FilePathtxtbx.Text); for (var i = rangefrom; i <= rangeto; i++) { //define search criteria string searchterm = "private"; StringComparison comparison = StringComparison.InvariantCulture; //create instance of XDocument //define parent node for ObjectType nodes var otsparent = xdoc.Descendants("Types").SingleOrDefault(); var eosparent = xdoc.Descendants("ExportedObjects").SingleOrDefault(); //find ObjectType nodes Name starts with "private" var ots2copy = xdoc.Descendants("ObjectType") .Where(x => x.Attribute("Name").Value.StartsWith(searchterm, comparison)) .ToList(); var eos2copy = xdoc.Descendants("OI") .Where(x => x.Attribute("TYPE").Value.StartsWith(searchterm, comparison)) .ToList(); var eos = xdoc.Descendants("OI"); //loop through the list of nodes which meet criteria //int i = 1; foreach (XElement original in ots2copy) { //create deep copy of original node XElement copy = new XElement(original); //change Name attribute copy.Attribute("Name").Value += i.ToString(); //add a copy to parent node otsparent.Add(copy); //i++; } //int j = 1; foreach (XElement original in eos2copy) { //create deep copy of original node XElement copy = new XElement(original); //change Name attribute //if (copy.Attribute("TYPE").Value.StartsWith(searchterm, comparison)) //{ // copy.Attribute("TYPE").Value += i.ToString(); //GETTING OUT OF MEMORY EXCEPTION HERE WITH VALUE private.*1111111111111111111111111111111111........... // //add a copy to parent node // eosparent.Add(copy); //} //j++; copy.Attribute("TYPE").Value += i.ToString(); //add a copy to parent node eosparent.Add(copy); //j++; } }
type
ExportedObjects
IF
startswith
"private.*"
TYPE