Descarte tags html em tags personalizadas ao obter texto em XHTML usando o SAX Parser no Groovy
Então, eu estou tentando obter o texto entre as tags. Até agora eu tenho tido sucesso. Mas, às vezes, quando há caracteres especiais ou tags html nas minhas tags personalizadas, não consigo obter o texto. O xml de amostra parece
<records>
<car name='HSV Maloo' make='Holden' year='2006'>
<ae_definedTermTitleBegin />Australia<ae_definedTermTitleEnd />
<ae_clauseTitleBegin />1.02 <u>Accounting Terms</u>.<ae_clauseTitleEnd />
</car>
<car name='P50' make='Peel' year='1962'>
<ae_definedTermTitleBegin />Isle of Man<ae_definedTermTitleEnd />
<ae_clauseTitleBegin />Smallest Street-Legal Car at 99cm wide and 59 kg in weight<ae_clauseTitleEnd />
</car>
<car name='Royale' make='Bugatti' year='1931'>
<ae_definedTermTitleBegin />France<ae_definedTermTitleEnd />
<ae_clauseTitleBegin />Most Valuable Car at $15 million<ae_clauseTitleEnd />
</car>
</records>
A saída que estou recebendo é
[Australia, Isle of Man, France]
[., Smallest Street-Legal Car at 99cm wide and 59 kg in weight, Most Valuable Car at $15 million]
Como você pode ver, faltam "Termos de contabilidade". Tudo o que recebo é um ponto. Como faço para corrigir isso?
O código do analisador de sax
import javax.xml.parsers.SAXParserFactory
import org.xml.sax.helpers.DefaultHandler
import org.xml.sax.*
class SAXXMLParser extends DefaultHandler {
def DefinedTermTitles = []
def ClauseTitles = []
def currentMessage
def countryFlag = false
void startElement(String ns, String localName, String qName, Attributes atts) {
switch (qName) {
case 'ae_clauseTitleBegin':
//messages.add(currentMessage)
countryFlag = true;
break
case 'ae_definedTermTitleBegin':
//messages.add(currentMessage)
countryFlag = true;
break
}
}
void characters(char[] chars, int offset, int length) {
if (countryFlag) {
currentMessage = new String(chars, offset, length)
println(currentMessage)
}
}
void endElement(String ns, String localName, String qName) {
switch (qName) {
case 'ae_clauseTitleEnd':
ClauseTitles.add(currentMessage)
countryFlag = false;
break
case 'ae_definedTermTitleEnd':
DefinedTermTitles.add(currentMessage)
countryFlag = false;
break
}
}
}