0

フラット ファイルから xml を読み取り、XmlSlurper を使用して解析します。XMLファイルは次のようになります

<ClientInformation>
<ContractClientVO>
 <AssignmentReasonCT></AssignmentReasonCT>
 <Associated></Associated>
 <AuthorizedSignatureCT></AuthorizedSignatureCT>
 <ClassCT></ClassCT>
 <RelationshipToInsuredCT></RelationshipToInsuredCT>
 <RelationshipToEmployeeCT></RelationshipToEmployeeCT>
 <ClientRoleVO>
  <AgentFK></AgentFK>
  <Associated></Associated>
  <RoleTypeCT></RoleTypeCT>
  <ClientDetailVO>
    <address></address>
    <city></city>
    <state></state>
    <Amount></Amount>
  </ClientDetailVO>
 </ClientRoleVO>
</ContractClientVO>
</ClientInformation>

XmlSlurper はそれを正しく読み取り、XML ドキュメントを出力します。ただし、XML 要素をナビゲートしません。

def xml = new XmlSlurper().parseText(file)
println XmlUtil.serialize(xml) //outputs fine on console
println xml.ClientInformation.size() //outputs 0
4

1 に答える 1

1

あなたの例では(xmlを有効に修正したら)、変数xmlはドキュメントのルートノードを表しますClientInformation

だから呼び出す:

xml.ClientInformation

何も返しません (ClientInformationという子がないためClientInformation)

ルート ドキュメント タグの子の数を取得するには、次のようにするだけです。

println xml.size()
于 2013-09-18T13:31:00.327 に答える