public static void createDoc(String filename){
/** document */
Document document = DocumentHelper.createDocument();
document.addElement("ADI");//
Element rootElement = document.getRootElement();
rootElement.addAttribute(rootAttribute, rootAttributeValue);
rootElement.addElement("Objects");
rootElement.addElement("Mappings");
try {
/** document -- */
File file = new File(filename);
FileWriter fw = new FileWriter(file);
XMLWriter writer = new XMLWriter(fw);//dom4j writer
writer.write(document);
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
*
* @Description XML , , document, , null
* @param filepath
* @return
* Document
* @throws
*/
public static Document getDoc(String filepath) {
Document document = null;
SAXReader reader = new SAXReader();
try {
File file = new File(filepath);
if(file.exists()){
document = reader.read(file);
}else{
return null;
}
} catch (Exception e) {
}
return document;
}
public static Element getObjects(Document doc){
Element rootElement = doc.getRootElement();
Element objects = rootElement.element("Objects");
return objects;
}
Element object = objects.addElement("Object");
object.addAttribute("ElementType", pro.getElementType());
object.addAttribute("ID", pro.getCode());
object.addAttribute("Action", Actions.getAction(actionType));
Element nameProperty = obj.addElement("Property");
nameProperty.addAttribute("Name", name);
nameProperty.addText(value);