从平面文件中读取 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