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){ |
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(); |
51 |
|
xmlData = "<"+rootInfo+">"; |
52 |
|
hostInfo = rootInfo; |
53 |
|
} |
62 |
|
hostInfo = null; |
63 |
|
} |
64 |
|
|
52 |
– |
|
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 |
80 |
|
* |
81 |
|
*/ |
95 |
|
xmlData += "<"+name+">"; |
96 |
|
myStack.push(name); |
97 |
|
} |
98 |
+ |
|
99 |
+ |
/** |
100 |
+ |
* addString, adds a string into the XML packet no further processing is carried out |
101 |
+ |
*/ |
102 |
+ |
public void addString(String name){ |
103 |
+ |
xmlData += name; |
104 |
+ |
} |
105 |
+ |
|
106 |
|
|
107 |
|
/** |
108 |
|
* closeNest will close the currently opened nest (by writing </nest name> to |