Changeset 742 for xmlTools/trunk/posUpdate/XmlTools.cs
- Timestamp:
- Mar 26, 2013, 3:30:48 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
xmlTools/trunk/posUpdate/XmlTools.cs
r710 r742 10 10 private XmlDocument xdoc; 11 11 private string posElement, posParentElement; 12 13 /// <summary> 12 private bool noBackups; 13 14 14 /// Our constructor 15 /// <summary> 15 16 /// </summary> 16 17 /// <param name="file"></param> 17 18 /// <param name="posElement"></param> 18 19 /// <param name="posParentElement"></param> 19 public XmlTools(string posElement, string posParentElement = "" )20 public XmlTools(string posElement, string posParentElement = "", bool noBackups = false) 20 21 { 21 22 this.posElement = posElement; 22 23 this.posParentElement = posParentElement; 24 this.noBackups = noBackups; 23 25 } 24 26 … … 30 32 public void replaceAll(string file, string value, string valuePositions = "") 31 33 { 32 Util.backupFile(file); 33 loadXmlFile(file); 34 35 List<XmlNode> myElements = new List<XmlNode>(); 36 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements,this.posElement,this.posParentElement); //Returns all after "Oni" element 34 if (!this.noBackups) 35 { 36 Util.backupFile(file); 37 } 38 loadXmlFile(file); 39 40 List<XmlNode> myElements = new List<XmlNode>(); 41 Util.getAllSpecificElements(xdoc.DocumentElement, ref myElements, this.posElement, this.posParentElement); //Returns all after "Oni" element 37 42 38 43 if (valuePositions != "") … … 71 76 public void addValues(string file, string values) 72 77 { 73 Util.backupFile(file); 78 if (!this.noBackups) 79 { 80 Util.backupFile(file); 81 } 74 82 loadXmlFile(file); 75 83 … … 89 97 XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); 90 98 91 foreach(String myInputValue in myInputValues.myValues){ 99 foreach (String myInputValue in myInputValues.myValues) 100 { 92 101 bool alreadyExists = false; 93 102 foreach (String myXmlSubValue in myXmlSubValues.myValues) … … 103 112 if (!alreadyExists) 104 113 { 105 element.InnerText += " " +myInputValue;114 element.InnerText += " " + myInputValue; 106 115 } 107 116 } … … 119 128 public void replaceValue(string file, string oldValue, string newValue) 120 129 { 121 Util.backupFile(file); 130 if (!this.noBackups) 131 { 132 Util.backupFile(file); 133 } 122 134 loadXmlFile(file); 123 135 … … 135 147 XmlTextValue myXmlSubValues = new XmlTextValue(element.InnerText); 136 148 137 for(int i=0; i<myXmlSubValues.myValues.Count; i++){ 138 //Found a match with the old value? 139 if (myXmlSubValues.myValues[i] == oldValue) 140 { 141 //replace with the new match 142 myXmlSubValues.myValues[i] = newValue; 143 } 144 } 145 element.InnerText = myXmlSubValues.ToString(); 149 for (int i = 0; i < myXmlSubValues.myValues.Count; i++) 150 { 151 //Found a match with the old value? 152 if (myXmlSubValues.myValues[i] == oldValue) 153 { 154 //replace with the new match 155 myXmlSubValues.myValues[i] = newValue; 156 } 157 } 158 element.InnerText = myXmlSubValues.ToString(); 146 159 } 147 160 } … … 157 170 public void removeValues(string file, string values) 158 171 { 159 Util.backupFile(file); 172 if (!this.noBackups) 173 { 174 Util.backupFile(file); 175 } 160 176 loadXmlFile(file); 161 177 … … 177 193 foreach (String myInputValue in myInputValues.myValues) 178 194 { 179 for(int i=0; i<myXmlSubValues.myValues.Count; i++){ 195 for (int i = 0; i < myXmlSubValues.myValues.Count; i++) 196 { 180 197 //It already exists in the xml? 181 198 if (myInputValue == myXmlSubValues.myValues[i]) … … 202 219 public void changeValue(string file, string newValue, string valueRelation = "", string valuePositions = "") 203 220 { 204 Util.backupFile(file); 221 if (!this.noBackups) 222 { 223 Util.backupFile(file); 224 } 205 225 loadXmlFile(file); 206 226 … … 256 276 public void invert(string file) 257 277 { 258 Util.backupFile(file); 278 if (!this.noBackups) 279 { 280 Util.backupFile(file); 281 } 259 282 loadXmlFile(file); 260 283 … … 267 290 foreach (XmlNode element in myElements) //Returns all after "Oni" element 268 291 { 269 292 invertedOrder.Add(element.InnerText); 270 293 } 271 294 … … 310 333 if (pos > testFirstRealValue.myValues.Count - 1 || pos < 0) //Are positions valid for the current values? //-1 because starts at 0 311 334 { 312 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);335 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); 313 336 } 314 337 }
Note:
See TracChangeset
for help on using the changeset viewer.