我想获取具有重复元素的XML文档的XPath和值。
示例:
<Return>
<ReturnData>
<Person>
<Name>Yohanna</Name>
</Person>
<Person>
<Name>Jacoub</Name>
</Person>
</ReturnData>
</Return>
我想归还给我:
1. /Return/ReturnData/Person[1]/Name=Yohanna
2. /Return/ReturnData/Person[2]/Name=Jacoub
我以前有过不同的Java代码实现,但是从其他人那里得到了这个实现(@nazar_art)。但是当我从顶层检索Xpath和值时,所有值都返回为空/空。
外首循环:
Evaluate xpath expression: [/PayrollFormInfo/CompanyInfo/EmpSummary/SSN]
2015-08-24 16:10:19,646 : XPATH result is EMPTY, for next xpath [/PayrollFormInfo/CompanyInfo/EmpSummary/SSN]
Evaluate xpath expression: [/PayrollFormInfo/CompanyInfo/EmpSummary/IsStatutory]
2015-08-24 16:10:19,646 : XPATH result is EMPTY, for next xpath [/PayrollFormInfo/CompanyInfo/EmpSummary/IsStatutory]
Evaluate xpath expression: [/PayrollFormInfo/CompanyInfo/EmpSummary/HasPensionPlan]
2015-08-24 16:10:19,647 : XPATH result is EMPTY, for next xpath [/PayrollFormInfo/CompanyInfo/EmpSummary/HasPensionPlan]
Evaluate xpath expression: [/PayrollFormInfo/CompanyInfo/EmpSummary/EmployeeType]
2015-08-24 16:10:19,647 : XPATH result is EMPTY, for next xpath [/PayrollFormInfo/CompanyInfo/EmpSummary/EmployeeType]
Evaluate xpath expression: [/PayrollFormInfo/CompanyInfo/FederalReturnType]
2015-08-24 16:10:19,648 : XPATH result is EMPTY, for next xpath [/PayrollFormInfo/CompanyInfo/FederalReturnType]
Evaluate xpath expression: [/PayrollFormInfo/EmployeeInfo/EmployeeType]
第二次循环输出:
Here! []
Here! []
Here! []
Here! []
Here! []
Here! []
Here! []
Here! []
Here! []
我不明白出了什么问题?当元素明确具有值时,为什么它不能找到元素的值。
以下是正在评估的XML文件: