View Javadoc

1   /*
2    * Created on Apr 10, 2005 by davidson
3    */
4   package ca.spaz.util;
5   
6   import java.io.PrintStream;
7   import java.util.*;
8   
9   /***
10   * A super simple class for quickly outputting some XML
11   * 
12   * @author davidson
13   */
14  public class XMLNode {
15    String name;
16    HashMap attributes = new HashMap();
17    ArrayList children = new ArrayList();
18    
19    public XMLNode(String name) {
20       this.name = name;
21    }
22  
23    public void addAttribute(String key, String val) {
24       attributes.put(key, val);
25    }
26    
27    public void addChild(XMLNode node) {
28       children.add(node);
29    }
30    
31    /***
32     * Escape a string so that it's safe to put in XML
33     * @param str
34     * @return an escaped string, safe for XML.
35     */
36    public String escape(String str) {
37       str = str.replaceAll("&", "&");
38       str = str.replaceAll("\"", "&quote;");
39       str = str.replaceAll("<", "&lt;");
40       str = str.replaceAll(">", "&gt;");
41       return str;
42    }
43    
44    public void print(PrintStream out) {
45       
46    }
47    
48  }