0
我有一個XML模板文檔:的XmlSlurper命名空間不被使用
<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>
...
,我讀使用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}
我然後將值插入文檔:
triadDoc.TriadRouteInfo.RoutingCorrelationId = dto.getReportRevisionId()
...
和輸出:
writer.toString()
這是我的文檔的樣子:
<?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>
...
注意,黑社會命名空間似乎每個元素。有很多這些線(我只在這裏顯示一個)。我希望NS僅在頂部聲明,並通過黑社會提及:。我究竟做錯了什麼?