if (xml == null || xml.equals(""))
return null;
// send back command object
Command command = null;
try {
// find the outer most tag
// the '<type>' of xml command
String type = getType(xml);
if (type != null) {
command = new Command(type);
// cut out outer most 'type' tags
xml = removeOuterElementTags(xml);
} else {
// make a default, no-name command
command = new Command();
}
// parse the xml fragment
for (;;) {
/* end of parse? */
if (xml.length() <= 0)
break;
/* parse the element name and value */
String elementName = getType(xml);
String elementValue = get(elementName, xml);
/* add the name/value pair to the command */
command.add(elementName, elementValue);
/* remove the parsed element from the xml fragment */
xml = removeElement(elementName, xml);
}