Java DOM edit: Modifying Text by Cutting and Pasting
public void edit(Document doc) {
int length;
int count;
int offset;
Element root = doc.getDocumentElement();
Element place = (Element)root.getFirstChild();
Text name = (Text)place.getFirstChild().getFirstChild();
Text directions = (Text)place.getLastChild().getFirstChild();
length = name.getLength();
count = 4;
offset = length - 4;
name.deleteData(offset,count);
length = directions.getLength();
count = 6;
offset = length - count;
String bridge = directions.substringData(offset,count);
name.appendData(bridge);
count = 5;
offset = 4;
directions.deleteData(offset,count);
}
Related examples in the same category