PublicationIdNode extends DOMFragmentReader<DocumentId> { @Override public DocumentId read() { Node parentNode = document.selectSingleNode(FRAGMENT_PATH); if (parentNode == null) { return null; } DocumentId documentId = new DocumentIdNode(parentNode).read(); if (documentId != null) { documentId.setType(DocumentIdType.PUBLISHED); } return documentId; } PublicationIdNode(Document document); @Override DocumentId read();  }
@Test public void test() throws DocumentException, InvalidDataException { String xml = "<xml><biblio><publication-reference><document-id>\r\n" + "<country>US</country>\r\n" + "<doc-number>09855244</doc-number>\r\n" + "<kind>B2</kind>\r\n" + "<date>20180102</date>\r\n" + "</document-id></publication-reference></biblio></xml>"; Document doc = DocumentHelper.parseText(xml); DocumentId docId = new PublicationIdNode(doc).read(); DocumentId expectId = new DocumentId(CountryCode.US, "09855244", "B2"); expectId.setType(DocumentIdType.REGIONAL_FILING); expectId.setDate(new DocumentDate("20180102")); assertEquals(expectId, docId); }