--- xmlTools/trunk/posUpdate/XmlTools.cs 2013/03/21 10:43:10 714 +++ xmlTools/trunk/posUpdate/XmlTools.cs 2013/03/26 02:30:48 742 @@ -9,17 +9,19 @@ namespace xmlTools { private XmlDocument xdoc; private string posElement, posParentElement; + private bool noBackups; - /// /// Our constructor + /// /// /// /// /// - public XmlTools(string posElement, string posParentElement = "") + public XmlTools(string posElement, string posParentElement = "", bool noBackups = false) { this.posElement = posElement; this.posParentElement = posParentElement; + this.noBackups = noBackups; } /// @@ -29,11 +31,14 @@ namespace xmlTools /// public void replaceAll(string file, string value, string valuePositions = "") { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); List myElements = new List(); - Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements,this.posElement,this.posParentElement); //Returns all after "Oni" element + Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, this.posElement, this.posParentElement); //Returns all after "Oni" element if (valuePositions != "") { @@ -70,7 +75,10 @@ namespace xmlTools /// public void addValues(string file, string values) { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); XmlTextValue myInputValues = new XmlTextValue(values); @@ -88,7 +96,8 @@ namespace xmlTools } XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); - foreach(String myInputValue in myInputValues.myValues){ + foreach (String myInputValue in myInputValues.myValues) + { bool alreadyExists = false; foreach (String myXmlSubValue in myXmlSubValues.myValues) { @@ -102,7 +111,7 @@ namespace xmlTools //if it doesn't exists already let's add it if (!alreadyExists) { - element.InnerText += " "+myInputValue; + element.InnerText += " " + myInputValue; } } } @@ -118,7 +127,10 @@ namespace xmlTools /// public void replaceValue(string file, string oldValue, string newValue) { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); List myElements = new List(); @@ -134,15 +146,16 @@ namespace xmlTools } XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); - for(int i=0; i public void removeValues(string file, string values) { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); XmlTextValue myInputValues = new XmlTextValue(values); @@ -176,7 +192,8 @@ namespace xmlTools foreach (String myInputValue in myInputValues.myValues) { - for(int i=0; i public void changeValue(string file, string newValue, string valueRelation = "", string valuePositions = "") { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); XmlNumberValue xmlLastPos = null, newXmlLastPos = null; @@ -255,7 +275,10 @@ namespace xmlTools /// public void invert(string file) { - Util.backupFile(file); + if (!this.noBackups) + { + Util.backupFile(file); + } loadXmlFile(file); //Inverting the element order @@ -266,7 +289,7 @@ namespace xmlTools //Read all and save to the list foreach (XmlNode element in myElements) //Returns all after "Oni" element { - invertedOrder.Add(element.InnerText); + invertedOrder.Add(element.InnerText); } //Let's start taking from the list to new xml file (inverted order) @@ -309,7 +332,7 @@ namespace xmlTools { if (pos > testFirstRealValue.myValues.Count - 1 || pos < 0) //Are positions valid for the current values? //-1 because starts at 0 { - Program.printAppError(Program.appErrors.INVALID_POSITIONS_RANGE, "The positions values are not in the range of the value to replace (pos index < 0 or > newValueIndexesNumber).",true); + Program.printAppError(Program.appErrors.INVALID_POSITIONS_RANGE, "The positions values are not in the range of the value to replace (pos index < 0 or > newValueIndexesNumber).", true); } } }