I have this XML file I need to extract the HTML Code from "mono" element but I need the html tags. I need to use groovy programming language.
All the divs inside "mono" element are HTML Tags including the divs
thank you in advance.
<dataset>
<chapters>
<chapter id="700" name="Immunology">
<title>Immunology</title>
<monos>
<mono id="382727">
<div>
<h1>blah blah</h1>
</div>
<div>
<p>blah blah</p>
</div>
</mono>
</monos>
</chapter>
<chapter id="701" name="hematology">
<title>Inmuno Hematology</title>
<monos>
<mono id="blah blah">
<div>
<h1>blah blah</h1>
</div>
<div>
<div class="class1">blah blah</div>
</div>
</mono>
</monos>
</chapter>
</chapters>
</dataset>
I have tried :
import javax.xml.parsers.*;
xml = new XmlParser().parse("languages.xml")
println("There are " +xml.chapters.chapter.size() +" Chapters")
for (int i = 0; i < xml.chapters.chapter.size(); i++) {
def chapter = xml.chapters.chapter[i]
def chapterName = chapter.'@name'
println chapterName
println("---- Monos List ----\n\n")
for (int j = 0; j < chapter.monos.mono.size(); j++) {
def mono = chapter.monos.mono[j]
println("Mono Content: " + mono.toString());
}
println("---- End Monos List ----\n\n")
}
But I just get the following ouput:
There are 2 Chapters Immunology ---- Monos List ----
Mono Content: mono[attributes={id=382727}; value=[div[attributes={}; value=[h1[attributes={}; value=[blah blah]]]], div[attributes={}; value=[p[attributes={}; value=[blah blah]]]]]] ---- End Monos List ----
hematology ---- Monos List ----
Mono Content: mono[attributes={id=blah blah}; value=[div[attributes={}; value=[h1[attributes={}; value=[blah blah]]]], div[attributes={}; value=[div[attributes={class=class1}; value=[blah blah]]]]]] ---- End Monos List ----