I'm currently trying to parse a node in groovy which contains mixed text and nodes with text and I need to get the text in the right order for example:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<p>
The text has
<strong>nodes</strong>
which need to get parsed
</p>
</root>
Now I want it to parse so I get the whole text but can still edit the node. In this example I want the result:
The text has <b>nodes</b> which need to get parsed
If I could just get a list of all elements under the p
where I can test if its a node or text I would be happy, but I cant find any way to get that.
Here You have working example:
I guess it's impossible to do without
CDATA
tag.You can use XmlUtil and XmlParser like so:
ok, I found a solution I can use without any (tricky) workarounds. The thing ist, a
NodeChild
doesn't have a Method that gives you both child text and child nodes but aNode
does. To get one simply usechildNodes()
(because the slurper gives you aNodeChild
)This gives me the result:
Which means I can easily do whatever I want with my Nodes while they are still in the right order with the text