Skip to content

Commit ce99c62

Browse files
committed
Reimplemented remove methods in Element
1 parent dfb44e1 commit ce99c62

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

lib/xmljava.jar

19 Bytes
Binary file not shown.

src/com/maxprograms/xml/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
public class Constants {
1616

17-
public static final String VERSION = "1.3.0";
18-
public static final String BUILD = "20230609_1500";
17+
public static final String VERSION = "1.4.0";
18+
public static final String BUILD = "20231113_1047";
1919
}

src/com/maxprograms/xml/Element.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,33 @@ public void removeAttribute(String attributeName) {
287287
}
288288

289289
public void removeChild(String string) {
290+
List<XMLNode> newContent = new Vector<>();
290291
for (int i = 0; i < content.size(); i++) {
291292
XMLNode node = content.get(i);
292-
if (node.getNodeType() == XMLNode.ELEMENT_NODE && ((Element) node).getName().equals(string)) {
293-
content.remove(node);
293+
if (node.getNodeType() == XMLNode.ELEMENT_NODE) {
294+
Element e = (Element) node;
295+
if (string.equals(e.getName())) {
296+
continue;
297+
}
294298
}
299+
newContent.add(node);
295300
}
301+
content = newContent;
296302
}
297303

298304
public void removeChild(Element child) {
305+
List<XMLNode> newContent = new Vector<>();
299306
for (int i = 0; i < content.size(); i++) {
300307
XMLNode node = content.get(i);
301-
if (node.getNodeType() == XMLNode.ELEMENT_NODE && ((Element) node).equals(child)) {
302-
content.remove(node);
303-
return;
308+
if (node.getNodeType() == XMLNode.ELEMENT_NODE) {
309+
Element e = (Element) node;
310+
if (child.equals(e)) {
311+
continue;
312+
}
304313
}
314+
newContent.add(node);
305315
}
316+
content = newContent;
306317
}
307318

308319
public void setAttribute(String attributeName, String value) {
@@ -372,12 +383,18 @@ public List<PI> getPI(String target) {
372383
}
373384

374385
public void removePI(String string) {
386+
List<XMLNode> newContent = new Vector<>();
375387
for (int i = 0; i < content.size(); i++) {
376388
XMLNode node = content.get(i);
377-
if (node.getNodeType() == XMLNode.PROCESSING_INSTRUCTION_NODE && ((PI) node).getTarget().equals(string)) {
378-
content.remove(node);
389+
if (node.getNodeType() == XMLNode.PROCESSING_INSTRUCTION_NODE) {
390+
PI pi = (PI) node;
391+
if (string.equals(pi.getTarget())) {
392+
continue;
393+
}
379394
}
395+
newContent.add(node);
380396
}
397+
content = newContent;
381398
}
382399

383400
public String getPrefix() {

0 commit comments

Comments
 (0)