@Test public void testAddAllChannels() { Document document; String xml = "<bookstore> <channel> <title>Everyday Italian</title> " + "<author>Giada De Laurentiis</author> " + "<year>2005</year> " + "<price>30.00</price> " + "</channel> " + "<channel> <title>Harry Potter</title> " + "<author>J K. Rowling</author>" + " <year>2005</year> " + "<price>29.99</price> </channel>" + " <channel> <title>XQuery Kick Start</title> " + "<author>James McGovern</author> " + " <author>Per Bothner</author> " + "<author>Kurt Cagle</author> " + "<author>James Linn</author> " + "<author>Vaidyanathan Nagarajan</author> " + "<year>2003</year> " + "<price>49.99</price> </channel> " + "<channel> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year>" + "<price>39.95</price> </channel> " + "</bookstore>"; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); document = documentBuilder.parse(is); } catch (Exception e) { throw new RuntimeException( "Unable to parse region metadata file: " + e.getMessage(), e); } NodeList bookstores = document.getElementsByTagName("bookstore"); nodes.addAllChannels(bookstores); Assert.assertEquals(4, nodes.getLength()); }
public void addAllChannels(NodeList root) { for (int i = 0; i < root.getLength(); i++) { Node cur = root.item(i); if ("channel".equals(cur.getNodeName())) { this.addItem(cur); } else { if (cur.getChildNodes() != null && cur.getChildNodes().getLength() > 0) { addAllChannels(cur.getChildNodes()); } } } }
TabListOfNodes implements NodeList { public void addAllChannels(NodeList root) { for (int i = 0; i < root.getLength(); i++) { Node cur = root.item(i); if ("channel".equals(cur.getNodeName())) { this.addItem(cur); } else { if (cur.getChildNodes() != null && cur.getChildNodes().getLength() > 0) { addAllChannels(cur.getChildNodes()); } } } } }
TabListOfNodes implements NodeList { public void addAllChannels(NodeList root) { for (int i = 0; i < root.getLength(); i++) { Node cur = root.item(i); if ("channel".equals(cur.getNodeName())) { this.addItem(cur); } else { if (cur.getChildNodes() != null && cur.getChildNodes().getLength() > 0) { addAllChannels(cur.getChildNodes()); } } } }  }
TabListOfNodes implements NodeList { public void addAllChannels(NodeList root) { for (int i = 0; i < root.getLength(); i++) { Node cur = root.item(i); if ("channel".equals(cur.getNodeName())) { this.addItem(cur); } else { if (cur.getChildNodes() != null && cur.getChildNodes().getLength() > 0) { addAllChannels(cur.getChildNodes()); } } } }  @Override int getLength(); @Override Node item(int index); void addItem(Node node); void addAllChannels(NodeList root); }
TabListOfNodes implements NodeList { public void addAllChannels(NodeList root) { for (int i = 0; i < root.getLength(); i++) { Node cur = root.item(i); if ("channel".equals(cur.getNodeName())) { this.addItem(cur); } else { if (cur.getChildNodes() != null && cur.getChildNodes().getLength() > 0) { addAllChannels(cur.getChildNodes()); } } } }  @Override int getLength(); @Override Node item(int index); void addItem(Node node); void addAllChannels(NodeList root);  }