0

XML に出現する無効な数値 (BTNumber) の出現回数を数えなければなりません。groovy XmlSlurper() を使用しています。数と数を数える方法を提案してください(xmlにある回数だけ)

例えば-

   BTNumber     | count
 ----------------------------------
   2205867438   |   2
   78124614     |   3

XMLコードは次のとおりです-

<Results>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2205867438
</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>2461253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:50:04.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2205867438</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>2461253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:50:18.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2201159526</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>1111253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:53:07.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>1011159526</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>1111253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:53:18.0</DateStamp>
</Row>
</Results>
 <Results>
  <Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>78124614</BTNumber>
    <CPNumber>78124614</CPNumber>
    <DialedNumber>7812461400</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>MyNetwork</CarrierCode>
    <DateStamp>2013-03-24 10:18:50.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>78124614</BTNumber>
    <CPNumber>78124614</CPNumber>
    <DialedNumber>7812461400</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>MyNetwork</CarrierCode>
    <DateStamp>2013-03-24 15:35:31.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>78124614</BTNumber>
    <CPNumber>78124614</CPNumber>
    <DialedNumber>7812461400</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>MyNetwork</CarrierCode>
    <DateStamp>2013-03-24 15:36:59.0</DateStamp>
</Row>
 </Results>

XMLSlurper よりも簡単で速いものがあれば提案してください。

4

2 に答える 2

1

まず、xml が繰り返されてい<Results>ます。それが必要ですか?

以下のようなものを使用して、一意idで対応するのマップを取得できcountます。

def xmlObj = new XmlSlurper().parseText(xml)
def btNumbers = xmlObj.Row.collect{it.BTNumber} 
def countMap = btNumbers.unique(false).collectEntries{btNumber-> 
    [btNumber, btNumbers.count(btNumber)]
}

xml問題で言及されているxml要素はどこにありますか。

<Results>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2205867438</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>2461253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:50:04.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2205867438</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>2461253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:50:18.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>2201159526</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>1111253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:53:07.0</DateStamp>
</Row>
<Row>
    <DialedCountry>001</DialedCountry>
    <BTNumber>1011159526</BTNumber>
    <CPNumber>0000000000</CPNumber>
    <DialedNumber>1111253052</DialedNumber>
    <Wireless>1</Wireless>
    <CarrierCode>customer1</CarrierCode>
    <DateStamp>2013-03-24 11:53:18.0</DateStamp>
</Row>
</Results>
于 2013-05-29T20:00:39.133 に答える