2009-05-29 5 views
3

Ich verwende Groovy XmlSlurper zu XHTML Dokument zu analysieren (oder Sudo XHTML eine), und ich versuche, zu den Text-Knoten des Dokuments zu bekommen, aber nicht herausfinden, wie, hier ist der Code:XmlSlurper - Liste Text und reguläre Knoten von XHTML-Dokument

import groovy.util.* 

xmlText = ''' 
<TEXTFORMAT INDENT="10" LEADING="-5"> 
    <P ALIGN="LEFT"> 
    <FONT FACE="Garamond Premr Pro" SIZE="20" COLOR="#001200" LETTERSPACING="0" KERNING="0"> 
     Less is more! this 
     <FONT COLOR="#FFFF00">should be all</FONT> 
     the 
     <FONT COLOR="#00FF00"> words OR should some </FONT> 
     OTHER WORDS will be there? 
    </FONT> 
    </P> 
</TEXTFORMAT> 
''' 
records = new XmlSlurper().parseText(xmlText) 
records.P.FONT.children().eachWithIndex {it, index -> println "${index} - ${it}"} 

, die die folgende Ausgabe zu drucken:

0 - should be all 
1 - words OR should some 

Aber ich will es den Text-Knoten Inhalt als auch gedruckt werden, so dass die gewünschte Ausgabe ist:

0 - Less is more! this 
1 - should be all 
2 - the 
3 - words OR should some 
4 - OTHER WORDS will be there? 

Irgendwelche Ideen?

Antwort

4

Sieht aus wie XmlSlurper nicht über separate Methode „Mixed Content“

Es abzurufen ist ein offener Posten Methode unterstützt Mixed Inhalt hier hinzufügen ->Groovy JIRA

+0

yep es scheint, dass nur die XmlParser unterstützt diese Option – talg

Verwandte Themen