@Test public void testAttributes2LevelHetero() { String xml = "<root>\n" + "<a>\n <b a=\"x0\" b=\"y0\" />\n" + " <b a=\"x1\" b=\"y1\" />\n" + " <b a=\"x2\" b=\"y2\" />\n" + " </a>" + "<x>\n <b a=\"x4\" b=\"y4\" />\n" + " <b a=\"x5\" b=\"y5\" />\n" + " <b a=\"x6\" b=\"y6\" />\n" + " </x>" + "</root>"; XPathRecordReader rr = new XPathRecordReader("/root/a | /root/x"); rr.addField("a", "/root/a/b/@a", false); rr.addField("b", "/root/a/b/@b", false); rr.addField("a", "/root/x/b/@a", false); rr.addField("b", "/root/x/b/@b", false); final List<Map<String, Object>> a = new ArrayList<Map<String, Object>>(); final List<Map<String, Object>> x = new ArrayList<Map<String, Object>>(); rr.streamRecords( new StringReader(xml), new XPathRecordReader.Handler() { public void handle(Map<String, Object> record, String xpath) { if (record == null) return; if (xpath.equals("/root/a")) a.add(record); if (xpath.equals("/root/x")) x.add(record); } }); assertEquals(1, a.size()); assertEquals(1, x.size()); }