When you have data in XML and you want to erase the data without making it read by XML Object such as DOM, replacement with String was often used. That is the story at that time.
I replaced the tag I wanted to erase as follows.
python
String xmlStringData = getXMLfile();
xmlStringData = xmlStringData.replaceAll("<ABB000001.*?</ABB00001>", "");
Sometimes it didn't disappear. This is because, as the investigation proceeded, the data between the tags was a character string, and line feed data was sometimes included in the expected part of the regular expression "*".
In this case, processing was performed using Pattern's DOTALL mode.
python
import java.util.regex.Pattern;
String xmlStringData = getXMLfile();
xmlStringData = Pattern.compile("<ABB000001.*?</ABB00001>", Pattern.DOTALL).matcher(xmlStringData).replaceAll("");
I was able to replace it successfully and delete the tag.
Recommended Posts