01: package dom;
02:
03: import org.w3c.dom.Element;
04: import org.w3c.dom.Node;
05: import org.w3c.dom.NodeList;
06: import java.util.Vector;
07:
08: public class DOMSubDocument {
09:
10: protected Node oNode;
11:
12: // ----------------------------------------------------------
13:
14: private DOMSubDocument() {
15: }
16:
17: // ----------------------------------------------------------
18:
19: public DOMSubDocument(Node oRefNode) {
20: oNode = oRefNode;
21: }
22:
23: // ----------------------------------------------------------
24:
25: public Node getNode() {
26: return oNode;
27: }
28:
29: // ----------------------------------------------------------
30:
31: public Node getNode(String sNodeName) {
32: Node oCurrentNode = null;
33:
34: for (oCurrentNode = oNode.getFirstChild(); oCurrentNode != null; oCurrentNode = oCurrentNode
35: .getNextSibling())
36: if (Node.ELEMENT_NODE == oCurrentNode.getNodeType())
37: if (sNodeName.equals(oCurrentNode.getNodeName()))
38: break;
39:
40: if (oCurrentNode != null)
41: return oCurrentNode;
42: else
43: return null;
44: }
45:
46: // ----------------------------------------------------------
47:
48: public String getElement(String sElementName) {
49: Node oCurrentNode = null;
50: Node oFirstChild;
51:
52: for (oCurrentNode = oNode.getFirstChild(); oCurrentNode != null; oCurrentNode = oCurrentNode
53: .getNextSibling())
54: if (Node.ELEMENT_NODE == oCurrentNode.getNodeType())
55: if (sElementName.equals(oCurrentNode.getNodeName()))
56: break;
57:
58: if (oCurrentNode != null) {
59: oFirstChild = oCurrentNode.getFirstChild();
60:
61: if (oFirstChild != null)
62: return oFirstChild.getNodeValue();
63: else
64: return null;
65: } else
66: return null;
67: } // getElement()
68:
69: // ----------------------------------------------------------
70:
71: public Vector getElements(String sElementName) {
72: Node oCurrentNode = null;
73: Vector oVector = new Vector();
74:
75: for (oCurrentNode = oNode.getFirstChild(); oCurrentNode != null; oCurrentNode = oCurrentNode
76: .getNextSibling())
77: if (Node.ELEMENT_NODE == oCurrentNode.getNodeType())
78: if (sElementName.equals(oCurrentNode.getNodeName()))
79: oVector.addElement(oCurrentNode);
80: if (oVector.size() > 0)
81: return oVector;
82: else
83: return null;
84: } // getElement()
85:
86: }
|