root.addAttribute("xsi:noNamespaceSchemaLocation",
"http://www.ucr.uu.se/xmlschema/" + getSchema("textSchema"));
root.addElement("documentname").setText(getDocumentName().equals("") ? "All texts" : getDocumentName());
TextBean text;
Element textElement = null;
Element labelElement;
String id, lastId = "", currentId = "";
String type = "";
int c = 0;
for (Iterator it = col.iterator(); it.hasNext();) {
c++;
text = (TextBean) it.next();
currentId = text.getId();
if (lastId.equals(currentId) && textElement != null) {
//If same id, different language
labelElement = textElement.addElement("label");
labelElement.setText(text.getText());
labelElement.addAttribute("lang", text.getLanguageid());
} else {
textElement = root.addElement("text");
if (currentId.lastIndexOf("_") == -1) {
//No type was found
log.log(Level.WARN, currentId + " has no type!");
id = currentId;
} else {
//Type found from last underscore
type = getType(currentId);
if (type.equals("")) {
//No type found, correct in the resulting xml later!
id = currentId;
} else {
//Type found
id = currentId.substring(0, currentId.lastIndexOf("_"));
}
}
/*
prefix = getPrefix(currentId);
if (! prefix.equals("")) {
textElement.addElement("prefix").setText(prefix);
id = getId(true, currentId);
} else {
//No prefix
id = getId(false, currentId);
}*/
textElement.addElement("id").setText(id);
textElement.addElement("type").setText(type);
labelElement = textElement.addElement("label");
labelElement.setText(text.getText());
labelElement.addAttribute("lang", text.getLanguageid());
lastId = currentId;
}
}
return newDocument;