01: /*
02: * Piscator: a small SQL/XML search engine
03: * Copyright (C) 2007 Luk Morbee
04: *
05: * This program is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: */
19: package piscator.util;
20:
21: import javax.xml.transform.TransformerException;
22:
23: import org.w3c.dom.Node;
24:
25: import com.sun.org.apache.xpath.internal.XPathAPI;
26:
27: public class DomUtils {
28:
29: public static String getValue(Node node, String xpath) {
30: String value = null;
31: if (node != null) {
32: Node singleNode = null;
33: try {
34: singleNode = XPathAPI.selectSingleNode(node, xpath);
35: if (singleNode != null && singleNode.hasChildNodes()) {
36: value = singleNode.getFirstChild().getNodeValue();
37: }
38: } catch (TransformerException e) {
39: }
40: }
41: return value;
42: }
43:
44: }
|