У меня есть xml, как показано ниже, и я пытаюсь получить размер «TimeAccountDetail», но просто получаю 0, но ожидаю 2. Не знаю, что нужно сделать?
xml:
<?xml version='1.0' encoding='UTF-8'?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1>
<TimeAccountDetail>
<TimeAccountDetail>
<TimeAccount_externalCode>614dbcc89cb843129b5c3be26dbd2a22</TimeAccount_externalCode>
<bookingDate>2019-03-21T07:38:31</bookingDate>
<bookingType>ADJUSTMENT</bookingType>
<comment>This is my test1</comment>
<employeeTime>null</employeeTime>
<externalCode>MyTimeAccountDetail</externalCode>
<referenceObject>null</referenceObject>
</TimeAccountDetail>
</TimeAccountDetail>
<TimeAccountDetail>
<TimeAccountDetail>
<TimeAccount_externalCode>614dbcc89cb843129b5c3be26dbd2a22</TimeAccount_externalCode>
<bookingDate>2019-03-21T07:38:31</bookingDate>
<bookingType>ADJUSTMENT</bookingType>
<comment>This is my test2</comment>
<employeeTime>null</employeeTime>
<externalCode>MyTimeAccountDetail</externalCode>
<referenceObject>null</referenceObject>
</TimeAccountDetail>
</TimeAccountDetail>
</multimap:Message1>
</multimap:Messages>
Groovy:
def ns = new Namespace('xmlns:http://sap.com/xi/XI/SplitAndMerge', 'multimap')
def slurper = new XmlSlurper(false,true)
def payload = slurper.parse(new File("C:/Users/me/Documents/finalXML.xml"))
def payloadSize = payload.TimeAccountDetail.size()
println "size is ${payloadSize}"