I have an XML template document:
<TriadMessage xmlns="http://www.myco.com/02/11/2008/V1/TriadMessage.xsd"
xmlns:triad="http://www.myco.com/02/11/2008/V1/TriadTypes.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<TriadRouteInfo>
<triad:RoutingCorrelationId>new value goes here</triad:RoutingCorrelationId>
...
that I read using Groovy 1.7:
triadDoc = new XmlSlurper().parseText(xmlMessage).declareNamespace(
tm: "http://www.myco.com/02/11/2008/V1/TriadMessage.xsd",
triad: "http://www.myco.com/02/11/2008/V1/TriadTypes.xsd",
xsi: "http://www.w3.org/2001/XMLSchema-instance"
)
xmlBuilder = new StreamingMarkupBuilder()
writer = xmlBuilder.bind {mkp.yield triadDoc}
I then insert values into the document:
triadDoc.TriadRouteInfo.RoutingCorrelationId = dto.getReportRevisionId()
...
and output:
writer.toString()
This is what my document looks like:
<?xml version="1.0" encoding="UTF-8"?>
<tm:TriadMessage xmlns:tm="http://www.myco.com/02/11/2008/V1/TriadMessage.xsd">
<tm:TriadRouteInfo>
<triad:RoutingCorrelationId xmlns:triad="http://www.myco.com/02/11/2008/V1/TriadTypes.xsd">24670</triad:RoutingCorrelationId>
...
Notice that the triad namespace appears with each element. There are a lot of these lines (I only show one here). I want to have the NS declared at the top only and referred via triad: below. What am I doing wrong?