5 |
|
|
6 |
|
/** |
7 |
|
* Formats data into valid XML |
8 |
< |
* By calling either addElement() or addNest() you can use this |
9 |
< |
* class to create valid xml. When all elements have been added |
10 |
< |
* calling returnXML() will return a string containing the xml. |
8 |
> |
* By calling either addElement() or addNest() you can use |
9 |
> |
* this class to create valid xml. When all elements have |
10 |
> |
* been added calling returnXML() will return a string |
11 |
> |
* containing the xml. |
12 |
|
* |
13 |
|
* |
14 |
|
* @author $Author$ |
32 |
|
* Takes in one arguement which can contain any valid non xml character ( "<",">" ) |
33 |
|
* an example for rootInfo would be "Host" |
34 |
|
*/ |
35 |
+ |
public XMLFormatter(String rootInfo, String attributes){ |
36 |
+ |
|
37 |
+ |
myStack = new Stack(); |
38 |
+ |
xmlData = new String(); |
39 |
+ |
xmlData = "<"+rootInfo+" "+attributes+">"; |
40 |
+ |
hostInfo = rootInfo; |
41 |
+ |
} |
42 |
+ |
|
43 |
+ |
/** |
44 |
+ |
* Public Constructor for the class |
45 |
+ |
* Takes in one arguement which can contain any valid non xml character ( "<",">" ) |
46 |
+ |
* an example for rootInfo would be "Host" |
47 |
+ |
*/ |
48 |
|
public XMLFormatter(String rootInfo){ |
49 |
|
myStack = new Stack(); |
50 |
|
xmlData = new String(); |
62 |
|
hostInfo = null; |
63 |
|
} |
64 |
|
|
51 |
– |
/** |
52 |
– |
* Public Constructor for the class |
53 |
– |
* Takes a second parameter containing the root attributes. |
54 |
– |
*/ |
55 |
– |
public XMLFormatter(String rootInfo, String rootAttributes){ |
56 |
– |
myStack = new Stack(); |
57 |
– |
xmlData = new String(); |
58 |
– |
xmlData = "<"+rootInfo+" "+rootAttributes+">"; |
59 |
– |
hostInfo = rootInfo; |
60 |
– |
} |
61 |
– |
|
65 |
|
//---PUBLIC METHODS--- |
66 |
+ |
|
67 |
+ |
/** |
68 |
+ |
* addEement, adds an element to the XML string with attributes |
69 |
+ |
* |
70 |
+ |
*/ |
71 |
+ |
public void addElement(String name, String attributes, String value){ |
72 |
+ |
// check that the strings contain valid data first |
73 |
+ |
if (( name.length() != 0 ) && ( value.length() != 0 )){ |
74 |
+ |
xmlData += "<"+name+" "+attributes+">"+value+"</"+name+">"; |
75 |
+ |
} |
76 |
+ |
} |
77 |
|
|
78 |
|
/** |
79 |
|
* addEement, adds an element to the XML string |