Groovyを使用して次のファイルを解析しています。人の役割がループで処理されているにもかかわらず、私が使用するコードの部分は、出力の最後に人の役割を連結しています。ここで出力が解析されない解析が発生する
def Sample="""
<tptc:People xmlns:tptc="http://www.metadata.calcum-inc.com/stats/">
<tptc:Identifier>456-99088</tptc:Identifier>
<tptc:Name>The Grand Supper</tptc:Name>
<tptc:Person>
<tptc:PersonRole>
<tptc:PersonRoleCode>COMMANDER</tptc:PersonRoleCode>
<tptc:PersonRoleDescription>
IN CHARGE OF ARMY
</tptc:PersonRoleDescription>
</tptc:PersonRole>
<tptc:PersonRole>
<tptc:PersonRoleCode>CONDUCTOR</tptc:PersonRoleCode>
<tptc:PersonRoleDescription>
DIRECTS SYMPHONY
</tptc:PersonRoleDescription>
</tptc:PersonRole>
<tptc:PersonName>
<tptc:PersonFirstName>Jackie</tptc:PersonFirstName>
<tptc:PersonMiddleName>Wang</tptc:PersonMiddleName>
<tptc:PersonLastName>Mang</tptc:PersonLastName>
</tptc:PersonName>
<tptc:PersonAddress>
<tptc:PersonAddressLine1Text>String</tptc:PersonAddressLine1Text>
<tptc:PersonAddressLine2Text>String</tptc:PersonAddressLine2Text>
<tptc:PersonCityName>String</tptc:PersonCityName>
<tptc:PersonStateCode>String</tptc:PersonStateCode>
<tptc:PersonZip5Code>String</tptc:PersonZip5Code>
<tptc:PersonZip4Code>String</tptc:PersonZip4Code>
</tptc:PersonAddress>
<tptc:PersonTelephone>
<tptc:PersonAreaCode>String</tptc:PersonAreaCode>
<tptc:PersonTelephoneNumber>String</tptc:PersonTelephoneNumber>
<tptc:TelephoneTypeCode>String</tptc:TelephoneTypeCode>
</tptc:PersonTelephone>
<tptc:PersonTelephone>
<tptc:PersonAreaCode>String</tptc:PersonAreaCode>
<tptc:PersonTelephoneNumber>String</tptc:PersonTelephoneNumber>
<tptc:TelephoneTypeCode>String</tptc:TelephoneTypeCode>
</tptc:PersonTelephone>
</tptc:Person>
<tptc:Person>
<tptc:PersonRole>
<tptc:PersonRoleCode>First</tptc:PersonRoleCode>
<tptc:PersonRoleDescription>Best Best</tptc:PersonRoleDescription>
</tptc:PersonRole>
<tptc:PersonRole>
<tptc:PersonRoleCode>None</tptc:PersonRoleCode>
<tptc:PersonRoleDescription>Nonetity</tptc:PersonRoleDescription>
</tptc:PersonRole>
<tptc:PersonName>
<tptc:PersonFirstName>String</tptc:PersonFirstName>
<tptc:PersonMiddleName>String</tptc:PersonMiddleName>
<tptc:PersonLastName>String</tptc:PersonLastName>
</tptc:PersonName>
<tptc:PersonAddress>
<tptc:PersonAddressLine1Text>String</tptc:PersonAddressLine1Text>
<tptc:PersonAddressLine2Text>String</tptc:PersonAddressLine2Text>
<tptc:PersonCityName>String</tptc:PersonCityName>
<tptc:PersonStateCode>String</tptc:PersonStateCode>
<tptc:PersonZip5Code>String</tptc:PersonZip5Code>
<tptc:PersonZip4Code>String</tptc:PersonZip4Code>
</tptc:PersonAddress>
<tptc:PersonTelephone>
<tptc:PersonAreaCode>String</tptc:PersonAreaCode>
<tptc:PersonTelephoneNumber>
String
</tptc:PersonTelephoneNumber>
<tptc:TelephoneTypeCode>
String
</tptc:TelephoneTypeCode>
</tptc:PersonTelephone>
<tptc:PersonTelephone>
<tptc:PersonAreaCode>String</tptc:PersonAreaCode>
<tptc:PersonTelephoneNumber>
String
</tptc:PersonTelephoneNumber>
<tptc:TelephoneTypeCode>
String
</tptc:TelephoneTypeCode>
</tptc:PersonTelephone>
</tptc:Person>
</tptc:People>
"""
は、私が使用したコードの一部である:ここで
def People = new XmlSlurper().parseText(Sample).
declareNamespace('tptc':'http://www.metadata.calcum-inc.com/stats/')
// Person
People.Person.each
{
println it.PersonRole.each{ role->
println role.PersonRoleCode
println role.PersonRoleDescription
}
}
が出力されます。
COMMANDER
IN CHARGE OF ARMY
CONDUCTOR
DIRECTS SYMPHONY
COMMANDERIN CHARGE OF ARMYCONDUCTORDIRECTS SYMPHONY
First
Best Best
None
Nonetity
FirstBest BestNoneNonetity
Result: COMMANDERIN CHARGE OF ARMYCONDUCTORDIRECTS SYMPHONYJackieWangMangStringStringStringStringStringStringStringStringStringStringStringStringFirstBest BestNoneNonetityStringStringStringStringStringStringStringString
StringStringStringStringStringMANICString
それはPerson要素の出力のすべての残りの部分を連結しています。私はそれが私が気にしている要素を印刷するだけです。ループ内のコードそれを達成する方法はありますか?助けてください!
予想される出力は? – Rao