25 |
|
// Adds new values to an element |
26 |
|
void XmlTools::addValues(QString newValues){ |
27 |
|
|
28 |
< |
// Process all XmlFiles |
29 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
28 |
> |
try{ |
29 |
> |
// Process all XmlFiles |
30 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
31 |
|
|
32 |
< |
QStringList newValuesList, currValuesList; |
33 |
< |
QList<pugi::xml_node> elements; |
32 |
> |
QStringList newValuesList, currValuesList; |
33 |
> |
QList<pugi::xml_node> elements; |
34 |
|
|
35 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"add-values"); |
35 |
> |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"add-values"); |
36 |
|
|
37 |
< |
newValuesList=Util::qStringListFromSpacedString(newValues); |
37 |
> |
newValuesList=Util::qStringListFromSpacedString(newValues); |
38 |
|
|
39 |
< |
// Check how the elements will be fetched via element name or xpath expression |
40 |
< |
if(this->xPathExpression==""){ |
41 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
42 |
< |
} |
43 |
< |
else{ |
44 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
45 |
< |
} |
39 |
> |
// Check how the elements will be fetched via element name or xpath expression |
40 |
> |
if(this->xPathExpression==""){ |
41 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
42 |
> |
} |
43 |
> |
else{ |
44 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
45 |
> |
} |
46 |
|
|
47 |
< |
for(int j=0; j<elements.size(); j++){ |
47 |
> |
for(int j=0; j<elements.size(); j++){ |
48 |
|
|
49 |
< |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
49 |
> |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
50 |
|
|
51 |
< |
for(int k=0; k<newValuesList.size(); k++){ |
52 |
< |
if(currValuesList.contains(newValuesList[k])){ // If the current element already contains this value proceed to the next |
53 |
< |
continue; |
54 |
< |
} |
51 |
> |
for(int k=0; k<newValuesList.size(); k++){ |
52 |
> |
if(currValuesList.contains(newValuesList[k])){ // If the current element already contains this value proceed to the next |
53 |
> |
continue; |
54 |
> |
} |
55 |
|
|
56 |
< |
elements[j].text()=QString(Util::toQString(elements[j].text().as_string()) + " " + newValuesList[k]).toUtf8().constData(); // If it doesn't exists yet let's add it |
56 |
> |
elements[j].text()=QString(Util::toQString(elements[j].text().as_string()) + " " + newValuesList[k]).toUtf8().constData(); // If it doesn't exists yet let's add it |
57 |
> |
} |
58 |
|
} |
57 |
– |
} |
59 |
|
|
60 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document,"add-values"); |
60 |
> |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document,"add-values"); |
61 |
> |
} |
62 |
> |
} |
63 |
> |
catch(const std::exception &e){ |
64 |
> |
UtilXmlTools::displayErrorMessage("add-values", QString("An exception was caught: ") + e.what()); |
65 |
|
} |
66 |
|
|
67 |
|
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(), "add-values"); |
70 |
|
|
71 |
|
void XmlTools::removeValues(QString valuesToRemove){ |
72 |
|
|
73 |
< |
// Process all XmlFiles |
74 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
75 |
< |
|
76 |
< |
QList<pugi::xml_node> elements; |
77 |
< |
QStringList valuesToRemoveList, currValuesList; |
78 |
< |
bool elementChanged=false; |
79 |
< |
|
80 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "remove-values"); |
81 |
< |
|
82 |
< |
// Check how the elements will be fetched via element name or xpath expression |
83 |
< |
if(this->xPathExpression==""){ |
84 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
85 |
< |
} |
86 |
< |
else{ |
87 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
88 |
< |
} |
73 |
> |
try{ |
74 |
> |
// Process all XmlFiles |
75 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
76 |
> |
|
77 |
> |
QList<pugi::xml_node> elements; |
78 |
> |
QStringList valuesToRemoveList, currValuesList; |
79 |
> |
bool elementChanged=false; |
80 |
> |
|
81 |
> |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "remove-values"); |
82 |
> |
|
83 |
> |
// Check how the elements will be fetched via element name or xpath expression |
84 |
> |
if(this->xPathExpression==""){ |
85 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
86 |
> |
} |
87 |
> |
else{ |
88 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
89 |
> |
} |
90 |
|
|
91 |
< |
valuesToRemoveList=Util::qStringListFromSpacedString(valuesToRemove); |
91 |
> |
valuesToRemoveList=Util::qStringListFromSpacedString(valuesToRemove); |
92 |
|
|
93 |
< |
for(int j=0; j<elements.size(); j++){ // O(3)... Optimization may be necessary. |
94 |
< |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
93 |
> |
for(int j=0; j<elements.size(); j++){ // O(3)... Optimization may be necessary. |
94 |
> |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
95 |
|
|
96 |
< |
for(int k=0; k<currValuesList.size(); k++){ |
97 |
< |
for(int m=0; m<valuesToRemoveList.size(); m++){ |
98 |
< |
if(currValuesList[k]==valuesToRemoveList[m]){ |
99 |
< |
currValuesList[k]=""; // flag to deletion |
100 |
< |
elementChanged=true; |
96 |
> |
for(int k=0; k<currValuesList.size(); k++){ |
97 |
> |
for(int m=0; m<valuesToRemoveList.size(); m++){ |
98 |
> |
if(currValuesList[k]==valuesToRemoveList[m]){ |
99 |
> |
currValuesList[k]=""; // flag to deletion |
100 |
> |
elementChanged=true; |
101 |
> |
} |
102 |
|
} |
103 |
|
} |
97 |
– |
} |
104 |
|
|
105 |
< |
if(elementChanged){ // If curr element changed update the XML |
106 |
< |
currValuesList.removeAll(""); // remove all files flagged to deletion |
107 |
< |
elements[j].text()=currValuesList.join(' ').toUtf8().constData(); |
108 |
< |
elementChanged=false; |
105 |
> |
if(elementChanged){ // If curr element changed update the XML |
106 |
> |
currValuesList.removeAll(""); // remove all files flagged to deletion |
107 |
> |
elements[j].text()=currValuesList.join(' ').toUtf8().constData(); |
108 |
> |
elementChanged=false; |
109 |
> |
} |
110 |
|
} |
104 |
– |
} |
111 |
|
|
112 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "remove-values"); |
112 |
> |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "remove-values"); |
113 |
> |
} |
114 |
> |
} |
115 |
> |
catch(const std::exception &e){ |
116 |
> |
UtilXmlTools::displayErrorMessage("remove-values", QString("An exception was caught: ") + e.what()); |
117 |
|
} |
108 |
– |
|
118 |
|
|
119 |
|
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(),"remove-values"); |
120 |
|
} |
121 |
|
|
122 |
|
void XmlTools::replaceValue(QString oldValue, QString newValue){ |
123 |
|
|
124 |
< |
// Process all XmlFiles |
125 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
126 |
< |
|
127 |
< |
QList<pugi::xml_node> elements; |
128 |
< |
QStringList currValuesList; |
129 |
< |
bool elementChanged=false; |
130 |
< |
|
131 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-value"); |
124 |
> |
try{ |
125 |
> |
// Process all XmlFiles |
126 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
127 |
> |
|
128 |
> |
QList<pugi::xml_node> elements; |
129 |
> |
QStringList currValuesList; |
130 |
> |
bool elementChanged=false; |
131 |
> |
|
132 |
> |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-value"); |
133 |
> |
|
134 |
> |
// Check how the elements will be fetched via element name or xpath expression |
135 |
> |
if(this->xPathExpression==""){ |
136 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
137 |
> |
} |
138 |
> |
else{ |
139 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
140 |
> |
} |
141 |
|
|
142 |
< |
// Check how the elements will be fetched via element name or xpath expression |
143 |
< |
if(this->xPathExpression==""){ |
126 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
127 |
< |
} |
128 |
< |
else{ |
129 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
130 |
< |
} |
142 |
> |
for(int j=0; j<elements.size(); j++){ |
143 |
> |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
144 |
|
|
145 |
< |
for(int j=0; j<elements.size(); j++){ |
146 |
< |
currValuesList=Util::qStringListFromSpacedString(Util::toQString(elements[j].text().as_string())); // convert each element in a list (uses space as separator) |
145 |
> |
for(int k=0; k<currValuesList.size(); k++){ |
146 |
> |
if(currValuesList[k]==oldValue){ // Found a match with the old value? |
147 |
> |
currValuesList[k]=newValue; // If found replace it with the new value |
148 |
> |
elementChanged=true; |
149 |
> |
} |
150 |
> |
} |
151 |
|
|
152 |
< |
for(int k=0; k<currValuesList.size(); k++){ |
153 |
< |
if(currValuesList[k]==oldValue){ // Found a match with the old value? |
137 |
< |
currValuesList[k]=newValue; // If found replace it with the new value |
138 |
< |
elementChanged=true; |
152 |
> |
if(elementChanged){ // If curr element changed update the XML |
153 |
> |
elements[j].text()=currValuesList.join(" ").toUtf8().constData(); |
154 |
|
} |
155 |
+ |
elementChanged=false; |
156 |
|
} |
157 |
|
|
158 |
< |
if(elementChanged){ // If curr element changed update the XML |
143 |
< |
elements[j].text()=currValuesList.join(" ").toUtf8().constData(); |
144 |
< |
} |
145 |
< |
elementChanged=false; |
158 |
> |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "replace-value"); |
159 |
|
} |
160 |
< |
|
161 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "replace-value"); |
160 |
> |
} |
161 |
> |
catch(const std::exception &e){ |
162 |
> |
UtilXmlTools::displayErrorMessage("replace-value", QString("An exception was caught: ") + e.what()); |
163 |
|
} |
164 |
|
|
165 |
|
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(), "replace-value"); |
168 |
|
// Replaces all current values of an element by another (can be specified only specific positions) |
169 |
|
void XmlTools::replaceAll(QString value, QString valuePositions){ |
170 |
|
|
171 |
< |
// Process all XmlFiles |
172 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
173 |
< |
|
160 |
< |
QList<pugi::xml_node> elements; |
161 |
< |
|
162 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-all"); |
171 |
> |
try{ |
172 |
> |
// Process all XmlFiles |
173 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
174 |
|
|
175 |
< |
// Check how the elements will be fetched via element name or xpath expression |
165 |
< |
if(this->xPathExpression==""){ |
166 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
167 |
< |
} |
168 |
< |
else{ |
169 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
170 |
< |
} |
175 |
> |
QList<pugi::xml_node> elements; |
176 |
|
|
177 |
+ |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "replace-all"); |
178 |
|
|
179 |
< |
// Let's start the override |
180 |
< |
for(int j=0; j<elements.size(); j++){ |
181 |
< |
if(valuePositions!=""){ |
176 |
< |
elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).toUtf8().constData(); |
179 |
> |
// Check how the elements will be fetched via element name or xpath expression |
180 |
> |
if(this->xPathExpression==""){ |
181 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
182 |
|
} |
183 |
|
else{ |
184 |
< |
elements[j].text()=value.toUtf8().constData(); |
184 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
185 |
> |
} |
186 |
> |
|
187 |
> |
|
188 |
> |
// Let's start the override |
189 |
> |
for(int j=0; j<elements.size(); j++){ |
190 |
> |
if(valuePositions!=""){ |
191 |
> |
elements[j].text()=replaceSpecificPositions(value, Util::toQString(elements[j].text().as_string()),valuePositions).toUtf8().constData(); |
192 |
> |
} |
193 |
> |
else{ |
194 |
> |
elements[j].text()=value.toUtf8().constData(); |
195 |
> |
} |
196 |
|
} |
181 |
– |
} |
197 |
|
|
198 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "replace-all"); |
198 |
> |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "replace-all"); |
199 |
> |
} |
200 |
> |
} |
201 |
> |
catch(const std::exception &e){ |
202 |
> |
UtilXmlTools::displayErrorMessage("replace-all", QString("An exception was caught: ") + e.what()); |
203 |
|
} |
204 |
|
|
205 |
|
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(), "replace-all"); |
210 |
|
// E.g. oldValue=5 , newValue=7; diffBetweenOldAndNewValue=-2 |
211 |
|
void XmlTools::updateElements(QString diffBetweenOldAndNewValue){ |
212 |
|
|
213 |
< |
// Process all XmlFiles |
214 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
215 |
< |
|
216 |
< |
QList<pugi::xml_node> elements; |
217 |
< |
MultiDimVar lastXmlValue(0); // inicialize with any value or dimension |
218 |
< |
MultiDimVar currXmlValue(0); |
219 |
< |
MultiDimVar newXmlValue(0); // value that will update currValue |
220 |
< |
|
221 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled, "update-elements"); |
222 |
< |
|
223 |
< |
// Check how the elements will be fetched via element name or xpath expression |
224 |
< |
if(this->xPathExpression==""){ |
225 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
226 |
< |
} |
227 |
< |
else{ |
228 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
229 |
< |
} |
213 |
> |
try{ |
214 |
> |
// Process all XmlFiles |
215 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
216 |
> |
|
217 |
> |
QList<pugi::xml_node> elements; |
218 |
> |
MultiDimVar lastXmlValue(0); // inicialize with any value or dimension |
219 |
> |
MultiDimVar currXmlValue(0); |
220 |
> |
MultiDimVar newXmlValue(0); // value that will update currValue |
221 |
> |
|
222 |
> |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled, "update-elements"); |
223 |
> |
|
224 |
> |
// Check how the elements will be fetched via element name or xpath expression |
225 |
> |
if(this->xPathExpression==""){ |
226 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
227 |
> |
} |
228 |
> |
else{ |
229 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
230 |
> |
} |
231 |
|
|
232 |
+ |
if(elements.size() > 0){ |
233 |
|
|
234 |
< |
if(elements.size()>1){ |
235 |
< |
lastXmlValue=MultiDimVar(Util::toQString(elements[0].text().as_string())); // the lastXmlValue will begin to be the first one of the node |
236 |
< |
currXmlValue=MultiDimVar(Util::toQString(elements[1].text().as_string())); // the currXmlValue will begin to be the second one of the node |
237 |
< |
newXmlValue=MultiDimVar::sub(lastXmlValue, MultiDimVar(diffBetweenOldAndNewValue)); |
238 |
< |
elements[0].text() = newXmlValue.toString().toUtf8().constData(); // update the first eblement with the new one already |
239 |
< |
} |
234 |
> |
lastXmlValue=MultiDimVar(Util::toQString(elements[0].text().as_string())); // the lastXmlValue will begin to be the first one of the node |
235 |
> |
newXmlValue=MultiDimVar::sub(lastXmlValue, MultiDimVar(diffBetweenOldAndNewValue)); |
236 |
> |
elements[0].text() = newXmlValue.toString().toUtf8().constData(); // update the first element with the new one already |
237 |
> |
|
238 |
> |
// If we have more than 1 element |
239 |
> |
if(elements.size()>1){ |
240 |
> |
currXmlValue=MultiDimVar(Util::toQString(elements[1].text().as_string())); // the currXmlValue will begin to be the second one of the node |
241 |
> |
|
242 |
> |
// Let's start the node update |
243 |
> |
for(int j=1; j<elements.size()-1; j++){ // We start in 1 because the 0 is already saved in lastXmlValue // -1 because we will also work with the next one in the current |
244 |
> |
|
245 |
> |
newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); |
246 |
> |
elements[j].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value |
247 |
> |
lastXmlValue=currXmlValue; |
248 |
> |
currXmlValue=MultiDimVar(Util::toQString(elements[j+1].text().as_string())); |
249 |
|
|
250 |
< |
// Let's start the node update |
221 |
< |
for(int j=1; j<elements.size()-1; j++){ // We start in 1 because the 0 is already saved in lastXmlValue // -1 because we will also work with the next one in the current |
250 |
> |
} |
251 |
|
|
252 |
< |
newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); |
253 |
< |
elements[j].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value |
254 |
< |
lastXmlValue=currXmlValue; |
255 |
< |
currXmlValue=MultiDimVar(Util::toQString(elements[j+1].text().as_string())); |
252 |
> |
// To update too last element (avoid out of bound because i+1) |
253 |
> |
newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); |
254 |
> |
elements[elements.size()-1].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value |
255 |
> |
} |
256 |
> |
} |
257 |
|
|
258 |
+ |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "update-elements"); |
259 |
|
} |
260 |
< |
|
261 |
< |
// To update too last element (avoid out of bound because i+1) |
262 |
< |
newXmlValue=MultiDimVar::sum(newXmlValue,MultiDimVar::sub(currXmlValue,lastXmlValue)); |
232 |
< |
elements[elements.size()-1].text() = newXmlValue.toString().toUtf8().constData(); // update element with the new value |
233 |
< |
|
234 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "update-elements"); |
260 |
> |
} |
261 |
> |
catch(const std::exception &e){ |
262 |
> |
UtilXmlTools::displayErrorMessage("update-elements", QString("An exception was caught: ") + e.what()); |
263 |
|
} |
264 |
|
|
265 |
< |
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(),"updateNode"); |
265 |
> |
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(),"update-elements"); |
266 |
|
|
267 |
|
} |
268 |
|
|
269 |
|
// Invert a set of XML elements with specified name (and optionally a parent name) |
270 |
|
void XmlTools::invertElements(){ |
271 |
|
|
272 |
< |
// Process all XmlFiles |
273 |
< |
for(int i=0; i<this->filesToProcess.size(); i++){ |
274 |
< |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "invert-elements"); |
275 |
< |
|
276 |
< |
QList<pugi::xml_node> elements; |
277 |
< |
QStringList invertedElements; //Inverting the element order |
272 |
> |
try{ |
273 |
> |
// Process all XmlFiles |
274 |
> |
for(int i=0; i<this->filesToProcess.size(); i++){ |
275 |
> |
UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, this->verboseEnabled, "invert-elements"); |
276 |
> |
|
277 |
> |
QList<pugi::xml_node> elements; |
278 |
> |
QStringList invertedElements; //Inverting the element order |
279 |
> |
|
280 |
> |
// Check how the elements will be fetched via element name or xpath expression |
281 |
> |
if(this->xPathExpression==""){ |
282 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
283 |
> |
} |
284 |
> |
else{ |
285 |
> |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
286 |
> |
} |
287 |
|
|
288 |
< |
// Check how the elements will be fetched via element name or xpath expression |
289 |
< |
if(this->xPathExpression==""){ |
290 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); |
291 |
< |
} |
255 |
< |
else{ |
256 |
< |
UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); |
257 |
< |
} |
288 |
> |
// Read all elements and save to the list |
289 |
> |
for(int j=elements.size()-1; j>=0; j--){ |
290 |
> |
invertedElements << Util::toQString(elements[j].text().as_string()); |
291 |
> |
} |
292 |
|
|
293 |
< |
// Read all elements and save to the list |
294 |
< |
for(int j=elements.size()-1; j>=0; j--){ |
295 |
< |
invertedElements << Util::toQString(elements[j].text().as_string()); |
296 |
< |
} |
293 |
> |
// Override the tree with the inverted order |
294 |
> |
for(int j=0; j<elements.size(); j++){ |
295 |
> |
elements[j].text()= invertedElements[j].toUtf8().constData(); |
296 |
> |
} |
297 |
|
|
298 |
< |
// Override the tree with the inverted order |
265 |
< |
for(int j=0; j<elements.size(); j++){ |
266 |
< |
elements[j].text()= invertedElements[j].toUtf8().constData(); |
298 |
> |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "invert-elements"); |
299 |
|
} |
300 |
< |
|
301 |
< |
UtilXmlTools::saveXmlFile(this->filesToProcess[i],this->document, "invert-elements"); |
300 |
> |
} |
301 |
> |
catch(const std::exception &e){ |
302 |
> |
UtilXmlTools::displayErrorMessage("invert-elements", QString("An exception was caught: ") + e.what()); |
303 |
|
} |
304 |
|
|
305 |
|
UtilXmlTools::displaySuccessMessage(this->filesToProcess.size(),"invert-elements"); |