source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/util/DOMUtils.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 974 bytes
Line 
1package org.greenstone.gsdl3.gs3build.util;
2
3import org.w3c.dom.Document;
4import org.w3c.dom.Element;
5import org.w3c.dom.NamedNodeMap;
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Text;
9
10public class DOMUtils
11{
12 public static String getNodeAttribute(Node node, String attribute)
13 {
14 NamedNodeMap atts = node.getAttributes();
15 if (atts == null) {
16 return null;
17 }
18 Node attributeNode = atts.getNamedItem(attribute);
19 if (attributeNode == null) {
20 return null;
21 }
22 return attributeNode.getNodeValue();
23 }
24
25 public static String getNodeChildText(Node node)
26 {
27 StringBuffer fieldName = new StringBuffer();
28
29 NodeList fieldChildren = node.getChildNodes();
30 for (int f = 0; f < fieldChildren.getLength(); f ++) {
31 if (fieldChildren.item(f).getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
32 fieldName.append(fieldChildren.item(f).getNodeValue());
33 }
34 }
35 return fieldName.toString();
36 }
37}
Note: See TracBrowser for help on using the repository browser.