KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > io > xml > XomWriter


1 package com.thoughtworks.xstream.io.xml;
2
3 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
4 import nu.xom.Element;
5 import nu.xom.Attribute;
6
7 public class XomWriter implements HierarchicalStreamWriter {
8
9     private Element node;
10
11     public XomWriter(Element parentElement) {
12         this.node = parentElement;
13     }
14
15     public void startNode(String JavaDoc name) {
16         Element newNode = new Element(name);
17         node.appendChild(newNode);
18         node = newNode;
19     }
20
21     public void addAttribute(String JavaDoc name, String JavaDoc value) {
22         node.addAttribute(new Attribute(name, value));
23     }
24
25     public void setValue(String JavaDoc text) {
26         node.appendChild(text);
27     }
28
29     public void endNode() {
30         node = (Element) node.getParent();
31     }
32
33     public void flush() {
34         // don't need to do anything
35
}
36
37     public void close() {
38         // don't need to do anything
39
}
40
41     public HierarchicalStreamWriter underlyingWriter() {
42         return this;
43     }
44 }
45
Popular Tags