Question

I understand that XML document changes are not immediate when using Groovy's XMLSlurper and StreamingMarkupBuilder. However, I'm not happy having to do a lot of processing whenever I change a document. The only way I've gotten it to work is if I do this:

    ...
labDoc = new XmlSlurper().parseText(serializeXml(labDoc))
...
def String serializeXml(GPathResult xml){
XmlUtil.serialize(new StreamingMarkupBuilder().bind {
        mkp.declareNamespace("lab", "www.myco.com/LabDocument")
        mkp.yield labDoc
  } )
}

every time I append a new Node. There has to be a better way! Can anyone help?

Was it helpful?

Solution

XMLParser would be a better option as it allows for immediate feedback on the inserted nodes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top