我需要一个提示如何使正确的获得下一个interator
输入XML,如您所见,元素Header包含'X',而在下一个结构中则不包含。
我需要创建结构“item”,直到获得下一个值为X的标题。
<?xml version='1.0' encoding='UTF-8'?>
<ns0:XPTO">
<Entry>
<Header>X</Header>
<CompanyCode>SE01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<PostingDate>20220514</PostingDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>SEK</TransactionCurrency>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>5000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX100000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX110000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>79637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX120000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>39647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX130000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>79647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>6000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX140000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header>X</Header>
<CompanyCode>FI01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<PostingDate>20220514</PostingDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>300</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GO01XX0000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>100</CreditAmount>
<ProfitCentre>GO01XX2000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>79637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>100</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GO02B00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>39647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>300</CreditAmount>
<ProfitCentre>GO02P00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header>X</Header>
<CompanyCode>EE02</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<PostingDate>20220514</PostingDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GS03P00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
<Entry>
<Header></Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<PostingDate></PostingDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GS04B00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Entry>
</ns0:JournalEntryReportRequest>
我知道我只需要添加一些interator检查下一个标题作为'X' -1之前的'项目',以生成标题和项目的同一产品在一起,但不知道如何使它。
好极了:
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.xml.*
import java.nio.charset.StandardCharsets
def Message processData(Message message) {
Reader reader = message.getBody(Reader)
def JEReport= new XmlParser().parse(reader)
Writer writer = new StringWriter()
def indentPrinter = new IndentPrinter(writer, ' ')
def builder = new MarkupBuilder(indentPrinter)
builder.'ns0:Messages'('xmlns:ns0': 'urn:eurofarma:nimbi:fornecedor') {
'ns0:Messages1'{
'ns1:AtlasFX_root'('xmlns:ns0': 'urn:eurofarma:nimbi:fornecedor'){
def arrayEntry = JEReport.Entry
arrayEntry.collect { item->
'AtlasFX_row'{
'Header'
{
'CompanyCode' item.CompanyCode.text()
'EntryType' item.EntryType.text()
'JournalEntryDate' item.JournalEntryDate.text()
'DocumentHeaderText' item.DocumentHeaderText.text()
'TransactionCurrency' item.TransactionCurrency.text()
}
'Item'
{
'GLAccount' item.GLAccount.text()
'ItemText' item.ItemText.text()
'DebitAmount' item.DebitAmount.text()
'CreditAmount' item.CreditAmount.text()
'ProfitCentre' item.ProfitCentre.text()
'AssignmentNumber' item.AssignmentNumber.text()
'TradingPartner' item.TradingPartner.text()
}
}
}
}
}
}
message.setBody(writer.toString())
return message
}
如下所示,响应错误,生成许多空的结构标头。
<ns0:Messages xmlns:ns0='urn:eurofarma:nimbi:fornecedor'>
<ns0:Messages1>
<ns1:AtlasFX_root xmlns:ns0='urn:eurofarma:nimbi:fornecedor'>
<AtlasFX_row>
<Header>
<CompanyCode>SE01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>SEK</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>5000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX100000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX110000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>79637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX120000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>39647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX130000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>79647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>6000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX140000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode>FI01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>300</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GO01XX0000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>100</CreditAmount>
<ProfitCentre>GO01XX2000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>79637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>100</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GO02B00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>39647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>300</CreditAmount>
<ProfitCentre>GO02P00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode>EE02</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GS03P00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode></CompanyCode>
<EntryType></EntryType>
<JournalEntryDate></JournalEntryDate>
<DocumentHeaderText></DocumentHeaderText>
<TransactionCurrency></TransactionCurrency>
</Header>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GS04B00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
</ns1:AtlasFX_root>
</ns0:Messages1>
</ns0:Messages>
谢谢你的任何帮助。
预期结果:
<ns0:Messages xmlns:ns0='urn:eurofarma:nimbi:fornecedor'>
<ns0:Messages1>
<ns1:AtlasFX_root xmlns:ns0='urn:eurofarma:nimbi:fornecedor'>
<AtlasFX_row>
<Header>
<CompanyCode>SE01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>SEK</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>5000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX100000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX110000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
<Item>
<GLAccount>79637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GOXX120000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
<Item>
<GLAccount>39647500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GOXX130000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode>FI01</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>300</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GO01XX0000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>100</CreditAmount>
<ProfitCentre>GO01XX2000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
<AtlasFX_row>
<Header>
<CompanyCode>EE02</CompanyCode>
<EntryType>TB</EntryType>
<JournalEntryDate>20220514</JournalEntryDate>
<DocumentHeaderText>AtlasFX Hedge</DocumentHeaderText>
<TransactionCurrency>EUR</TransactionCurrency>
</Header>
<Item>
<GLAccount>16191800</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount>1000</DebitAmount>
<CreditAmount></CreditAmount>
<ProfitCentre>GS03P00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
<Item>
<GLAccount>39637500</GLAccount>
<ItemText>AtlasFX Hedge</ItemText>
<DebitAmount></DebitAmount>
<CreditAmount>1000</CreditAmount>
<ProfitCentre>GS04B00000</ProfitCentre>
<AssignmentNumber>AtlasFX Hedge</AssignmentNumber>
<TradingPartner>SE02</TradingPartner>
</Item>
</AtlasFX_row>
</ns1:AtlasFX_root>
</ns0:Messages1>
</ns0:Messages>
1条答案
按热度按时间alen0pnh1#
一个简化的可运行代码,它应该让您知道如何在迭代之前对数据进行分组
您转换可能如下所示: