- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
// Gets the starting position for the endtag of the first element in text.
private int getEndTagPosition(String element, String text) {
String startTag = "<" + element;
String endTag = "</" + element;
int nestingLevel = 1;
int end = 0;
int startPos = 1;
while (nestingLevel > 0) { // loop until matching endtag is found
int start = text.indexOf(startTag, startPos);
end = text.indexOf(endTag, startPos);
if ((start == -1) || (start > end)) { // next tag is an endtag
nestingLevel--;
startPos = end + 1;
} else { // next tag is a starttag
nestingLevel++;
startPos = start + 1;
}
}
return end;
}