Вот как это сделать с помощью lxml без необходимости жесткого кодирования пространств имен или сканирования текста для них (как упоминает Martijn Pieters):
from lxml import etree
tree = etree.parse("filename")
root = tree.getroot()
root.findall('owl:Class', root.nsmap)
deleteText(startIndex, endIndex)
для удаления текста. Посмотрите на код ниже:
public void start(Stage primaryStage) throws Exception {
int indexStart = 0; //initialize variables
int indexEnd = 0;
TextArea textArea = new TextArea();
textArea.setText("123\nhello\nabc\ntwentyone\n"); //initialize text in box
VBox vbox = new VBox(textArea);
Scene scene = new Scene(vbox, 200, 100);
primaryStage.setScene(scene);
primaryStage.show();
for(String line : textArea.getText().split("\n")){
if(line.contains("abc")) { //change this to whatever you need
indexStart = textArea.getText().indexOf(line.charAt(0));
indexEnd = indexStart + line.length()-1;
}
textArea.deleteText(indexStart, indexEnd); //Delete between indexes
}
}
public static void main(String[] args) {
Application.launch(args);
}