How to map two similar XML Element using XMLBeam?

2019-09-19 06:16发布

问题:

This is the format of the XML so it is difficult for me to grab the 2nd instance:

<sec2_Ind>
 <SectC_EntyType>
  <TextField3>1</TextField3>
 </SectC_EntyType>
 <nameInfo>
  <subName>
   <fName>Name 1</fName>
  </subName>
 </nameInfo>
 <SectC_EntyType>
  <TextField3>2</TextField3>
 </SectC_EntyType>
 <nameInfo>
  <subName>
   <fName>Name 2</fName>
  </subName>
 </nameInfo>
<sec2_Ind>

From above, I am only able to get the 1st instance details (Name 1) as the elements does not have unique identifier except for <TextField3>###</TextField3>

What is the proper @XBRead format as well?

回答1:

From your answer I guess that you want a list of Strings:

 @XBRead("//(TextField3 | fName)")
 List<String> getNames();