Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未使用XmlSlurper命名空间_Xml_Groovy - Fatal编程技术网

未使用XmlSlurper命名空间

未使用XmlSlurper命名空间,xml,groovy,Xml,Groovy,我有一个XML模板文档: <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>

我有一个XML模板文档:

<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>
...
triadDoc.TriadRouteInfo.RoutingCorrelationId = dto.getReportRevisionId()
...
然后,我在文档中插入值:

<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>
...
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>
...

24670
...
请注意,空间坐标轴名称空间与每个元素一起出现。这里有很多这样的行(我这里只显示一行)。我想让NS只在顶部声明,并通过triad:below引用。我做错了什么?

刚刚试过这个:

import groovy.xml.StreamingMarkupBuilder

def xml = """
<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>
  </TriadRouteInfo>
</TriadMessage>"""


def triadDoc = new XmlSlurper().parseText( xml ).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" )

def xmlBuilder = new StreamingMarkupBuilder()
writer = xmlBuilder.bind {
  mkp.declareNamespace( tm:    "http://www.myco.com/02/11/2008/V1/TriadMessage.xsd" )
  mkp.declareNamespace( triad: "http://www.myco.com/02/11/2008/V1/TriadTypes.xsd" )
  mkp.declareNamespace( xsi:   "http://www.w3.org/2001/XMLSchema-instance" )
  mkp.yield triadDoc
}

triadDoc.TriadRouteInfo.RoutingCorrelationId = 'wheeee'

println writer
import groovy.xml.StreamingMarkupBuilder
def xml=“”
这里有新的价值
"""
def triadDoc=new XmlSlurper().parseText(xml).declareNamespace(
tm:“http://www.myco.com/02/11/2008/V1/TriadMessage.xsd", 
三合会:http://www.myco.com/02/11/2008/V1/TriadTypes.xsd", 
xsi:“http://www.w3.org/2001/XMLSchema-instance" )
def xmlBuilder=新StreamingMarkupBuilder()
writer=xmlBuilder.bind{
mkp.declareNamespace(tm:http://www.myco.com/02/11/2008/V1/TriadMessage.xsd" )
mkp.declareNamespace(三和弦):http://www.myco.com/02/11/2008/V1/TriadTypes.xsd" )
mkp.declareNamespace(xsi:http://www.w3.org/2001/XMLSchema-instance" )
mkp.triadDoc
}
Triadoc.TriadLoteInfo.RoutingCorrelationId='wheeee'
印刷机
它打印出了这个(我把它整理好了,所以它不全在一行上):


惠伊
有什么好处吗