サンプルのLEDESXMLファイルhttps://codebeautify.org/xmlviewer/cbdc79e7があり、請求書ノードのinv_id
値をキーとして、そのすべての子要素のfile_item_nbr
値を以下のようにマップを作成しようとしています。
['Invoice 31' : [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
'Invoice 32' : [50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73]
]
誰かがそれを手伝ってくれませんか?
sudoコードで取得できるはずです:
XmlSlurper
xmlを解析するために使用しますinvoice
要素を読むスクリプトは次のとおりです。
//Not putting entire xml here, just pass the xml as string to parseText method
def xml = new XmlSlurper().parseText(xmlString)
//Get the invoices
def invoices = xml.'**'.findAll{it.name() == 'invoice'}
//Build the desired result
println invoices.collectEntries {inv -> [(inv.inv_id): inv.'**'.findAll{it.name() == 'file_item_nbr'}*.text()] }
あなたはすぐにそれをオンラインで試すことができます demo
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加