获取XML子节点并使用;合并值;在Groovy

时间:2018-07-07 22:41:42

标签: string list groovy

我有下面的XML文档: xmlIn:

<SalesOrder>
<Parameter>Parameter1</Parametro>
<Method>Method1</Metodo>
<Orders>
<Order>
    <Salesman>44</Salesman>
    <Customer>12345</Customer>
    <OrderNumber>100200300</OrderNumber>
</Order>
<Order>
    <Salesman>45</Salesman>
    <Customer>67890</Customer>
    <OrderNumber>400500600</OrderNumber>
</Order>
</Orders>

我有一个在Groovy中转换为字符串的请求:

Field1; Field2; Field3

44; 12345; 100200300

45; 67890; 400500600

我的源代码是:

def parser = new XmlSlurper().parseText(xmlIn)
        String header = 'Field1;Field2;Field3'
        def lines = parser.Orders.Order.children().each { 
            it.text()
        }.join(";")
        prinln(header + "\n" + lines)

但是这正在产生:

Field1; Field2; Field3

44; 12345; 100200300; 45; 67890; 400500600

有人可以帮我吗?

非常感谢您!

1 个答案:

答案 0 :(得分:0)

    "contentDetails": {
       "duration": "PT1H11M47S",
       "dimension": "2d",
       "definition": "hd",
       "caption": "true",
       "licensedContent": false,
       "projection": "rectangular"
    }