KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > xml > XMLRoot


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 David Eng
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot.xml;
28
29
30 /** XML helper */
31 public class XMLRoot
32 {
33     public String JavaDoc name = ""; // <NAME attr1="val1" attr2="val2"...>val</NAME>
34
public String JavaDoc value = ""; // <name attr1="val1" attr2="val2"...>VAL</name>
35
public String JavaDoc[] attributes = { "" }; // <name ATTR1="val1" ATTR2="val2"...>val</name>
36
public String JavaDoc[] values = { "" }; // <name attr1="VAL1" attr2="VAL2"...>val</name>
37

38     protected XMLNode child = null; // -> to child node
39

40     XMLRoot()
41     {
42     }
43
44     public String JavaDoc toString()
45     {
46         return XMLPrinter.xmlHeader + XMLPrinter.dtdHeader + this.child.toPostString();
47     }
48
49     // add element to end of tree
50
public XMLNode addElement( String JavaDoc name )
51     {
52         return addElement( name, "", "", "" );
53     }
54     public XMLNode addElement( String JavaDoc name, String JavaDoc value )
55     {
56         return addElement( name, value, "", "" );
57     }
58     public XMLNode addElement( String JavaDoc name, String JavaDoc value, String JavaDoc[] attributes )
59     {
60         return addElement( name, value, attributes, null );
61     }
62     public XMLNode addElement( String JavaDoc name, String JavaDoc[] attributes, String JavaDoc[] values )
63     {
64         return addElement( name, "", attributes, values );
65     }
66     public XMLNode addElement( String JavaDoc name, String JavaDoc value, String JavaDoc attribute, String JavaDoc attributeValue )
67     {
68         return addElement( name, value, new String JavaDoc[] { attribute}, new String JavaDoc[] { attributeValue} );
69     }
70     public XMLNode addElement( String JavaDoc name, String JavaDoc value, String JavaDoc[] attributes, String JavaDoc[] values )
71     {
72         XMLNode current= null;
73         XMLNode newnode = new XMLNode( name, value, attributes, values );
74         newnode.root = this;
75
76         if( this.child == null )
77         {
78             this.child = newnode;
79             newnode.parent = null; // root's children have NO PARENTS :(
80
}
81         else
82         {
83             current = this.child;
84             while( current.next != null )
85             {
86                 current = current.next;
87             }
88             current.next = newnode;
89             newnode.prev = current;
90         }
91         return newnode;
92     }
93 }
94
Popular Tags