@Test public void testSelectMultipleTextItems() throws Exception { XPath xpath = new XPath(SimpleNamespaceContext.create(SimpleNamespaceContextTest.createNamespaceEntries())); Document d = XmlHelper.createDocument(XML, DocumentBuilderFactoryBuilder.newInstance()); String[] vals = xpath.selectMultipleTextItems(d, "/root/test"); assertEquals(2, vals.length); assertEquals("one", vals[0]); assertEquals("two", vals[1]); }
public String[] selectMultipleTextItems(Node context, String xpath) throws XPathExpressionException { NodeList list = selectNodeList(context, xpath); String[] retArray = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { retArray[i] = node.getNodeValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { retArray[i] = node.getNodeValue(); } else { node.normalize(); Node text = node.getFirstChild(); if (text != null) { retArray[i] = text.getNodeValue(); } } } } return retArray; }
XPath { public String[] selectMultipleTextItems(Node context, String xpath) throws XPathExpressionException { NodeList list = selectNodeList(context, xpath); String[] retArray = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { retArray[i] = node.getNodeValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { retArray[i] = node.getNodeValue(); } else { node.normalize(); Node text = node.getFirstChild(); if (text != null) { retArray[i] = text.getNodeValue(); } } } } return retArray; } }
XPath { public String[] selectMultipleTextItems(Node context, String xpath) throws XPathExpressionException { NodeList list = selectNodeList(context, xpath); String[] retArray = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { retArray[i] = node.getNodeValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { retArray[i] = node.getNodeValue(); } else { node.normalize(); Node text = node.getFirstChild(); if (text != null) { retArray[i] = text.getNodeValue(); } } } } return retArray; } XPath();  XPath(NamespaceContext ctx);  XPath(NamespaceContext ctx, XPathFactory factory); }
XPath { public String[] selectMultipleTextItems(Node context, String xpath) throws XPathExpressionException { NodeList list = selectNodeList(context, xpath); String[] retArray = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { retArray[i] = node.getNodeValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { retArray[i] = node.getNodeValue(); } else { node.normalize(); Node text = node.getFirstChild(); if (text != null) { retArray[i] = text.getNodeValue(); } } } } return retArray; } XPath();  XPath(NamespaceContext ctx);  XPath(NamespaceContext ctx, XPathFactory factory); String selectSingleTextItem(Node context, String xpath); String[] selectMultipleTextItems(Node context, String xpath); NodeList selectNodeList(Node context, String xpath); Node selectSingleNode(Node context, String xpath); static XPathFactory newXPathFactory(); static XPath newXPathInstance(DocumentBuilderFactoryBuilder builder, NamespaceContext namespaceCtx); static XPath newXPathInstance(DocumentBuilderFactory builder, NamespaceContext namespaceCtx); }
XPath { public String[] selectMultipleTextItems(Node context, String xpath) throws XPathExpressionException { NodeList list = selectNodeList(context, xpath); String[] retArray = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { retArray[i] = node.getNodeValue(); } else if (node.getNodeType() == Node.TEXT_NODE) { retArray[i] = node.getNodeValue(); } else { node.normalize(); Node text = node.getFirstChild(); if (text != null) { retArray[i] = text.getNodeValue(); } } } } return retArray; } XPath();  XPath(NamespaceContext ctx);  XPath(NamespaceContext ctx, XPathFactory factory); String selectSingleTextItem(Node context, String xpath); String[] selectMultipleTextItems(Node context, String xpath); NodeList selectNodeList(Node context, String xpath); Node selectSingleNode(Node context, String xpath); static XPathFactory newXPathFactory(); static XPath newXPathInstance(DocumentBuilderFactoryBuilder builder, NamespaceContext namespaceCtx); static XPath newXPathInstance(DocumentBuilderFactory builder, NamespaceContext namespaceCtx); static final String SYSPROP_USE_SAXON_XPATH; }