InventorNode extends DOMFragmentReader<List<Inventor>> { @Override public List<Inventor> read() { List<Inventor> inventorList = new ArrayList<Inventor>(); List<Node> applicantInventNodes = FRAG_PATH_APPLICANTX.selectNodes(document); if (applicantInventNodes.isEmpty()) { applicantInventNodes = FRAG_PATH_APPLICANT2X.selectNodes(document); } List<Inventor> applicantInventors = readInventors(applicantInventNodes); inventorList.addAll(applicantInventors); List<Node> inventors = FRAG_PATHX.selectNodes(document); if (inventors.isEmpty()) { inventors = FRAG_PATH2X.selectNodes(document); } List<Inventor> currentLocInventors = readInventors(inventors); inventorList.addAll(currentLocInventors); return inventorList; } InventorNode(Document document); @Override List<Inventor> read();  }
@Test public void Inventors() throws DocumentException { String xml = "<us-parties><inventors>\r\n" + "<inventor designation=\"us-only\" sequence=\"001\">\r\n" + "<addressbook>\r\n" + "<last-name>Doe</last-name>\r\n" + "<first-name>John</first-name>\r\n" + "<address>\r\n" + "<city>Portland</city>\r\n" + "<state>OR</state>\r\n" + "<country>US</country>\r\n" + "</address>\r\n" + "</addressbook>\r\n" + "</inventor>\r\n" + "<inventor designation=\"us-only\" sequence=\"002\">\r\n" + "<addressbook>\r\n" + "<last-name>Smith</last-name>\r\n" + "<first-name>John Paul</first-name>\r\n" + "<address>\r\n" + "<city>Albany</city>\r\n" + "<state>OR</state>\r\n" + "<country>US</country>\r\n" + "</address>\r\n" + "</addressbook>\r\n" + "</inventor></inventors></us-parties>"; Document doc = DocumentHelper.parseText(xml); List<Inventor> inventors = new InventorNode(doc).read(); assertEquals("Doe", ((NamePerson) inventors.get(0).getName()).getLastName()); assertEquals(CountryCode.US, inventors.get(0).getAddress().getCountry()); assertEquals("OR", inventors.get(0).getAddress().getState()); assertEquals("Portland", inventors.get(0).getAddress().getCity()); assertEquals("Smith", ((NamePerson) inventors.get(1).getName()).getLastName()); assertEquals(CountryCode.US, inventors.get(1).getAddress().getCountry()); assertEquals("OR", inventors.get(1).getAddress().getState()); assertEquals("Albany", inventors.get(1).getAddress().getCity()); }