本文整理匯總了Java中nu.xom.Document.getRootElement方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getRootElement方法的具體用法?Java Document.getRootElement怎麽用?Java Document.getRootElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nu.xom.Document
的用法示例。
在下文中一共展示了Document.getRootElement方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: importData
import nu.xom.Document; //導入方法依賴的package包/類
/**
* imports data from an xml file into the master psp file
* @param filePath the xml file to import
* @param overrideExistingElements determines if existing psp elements will be written over
* @return returns true if successful or false if the import process failed
*/
public static boolean importData(String filePath, boolean overrideExistingElements) {
PSP.refresh();
Document importDocument = null;
Element importRoot = null;
if (filePath == null || filePath.isEmpty()) {
Util.debug("The file path parameter passed to DataImporter.importData is null or empty.");
return false;
}
try {
if (new File(filePath).exists()) {
importDocument = FileStorage.openDocument(filePath);
importRoot = importDocument.getRootElement();
if (importRoot.getLocalName().equals("psp")) {
Elements importProjects = importRoot.getChildElements(PSP.ELEMENT_NAME);
if (importProjects != null) {
for (int i = 0; i < importProjects.size(); i++) {
Element importProject = importProjects.get(i);
String importProjectId = importProject.getAttributeValue(PSP.ID_ATTRIBUTE);
Elements homeProjects = PSP.root.getChildElements(PSP.ELEMENT_NAME);
boolean isNew = true;
Element homeProject = null;
if (homeProjects != null) {
for (int n = 0; n < homeProjects.size(); n++) {
String homeProjectId = homeProjects.get(n).getAttributeValue(PSP.ID_ATTRIBUTE);
if (homeProjectId.equals(importProjectId)) {
isNew = false;
homeProject = homeProjects.get(n);
break;
}
}
}
if (isNew) {
Node newProject = importProject.copy();
PSP.root.appendChild(newProject);
} else {
updateProject(importProject, homeProject, overrideExistingElements);
}
}
}
}
else {
throw new Exception("The root element is not psp.");
}
} else {
throw new Exception("The file " + filePath + " does not exist.");
}
}
catch (Exception e) {
Util.debug(e.getMessage() + " " + filePath);
e.printStackTrace();
return false;
}
return true;
}
示例2: upgrade1_1d1
import nu.xom.Document; //導入方法依賴的package包/類
private static void upgrade1_1d1(String[] projectIds) {
for (int i = 0; i < projectIds.length; i++) {
Util.debug("Upgrading project " + projectIds[i] + " from version 1.0 to version 1.1d1");
String filePath = FileStorage.JN_DOCPATH + projectIds[i] + File.separator + ".tasklist";
Document doc = FileStorage.openDocument(filePath);
Element root = doc.getRootElement();
Elements tasks = root.getChildElements("task");
for (int j = 0; j < tasks.size(); j++) {
Element task = tasks.get(j );
// Decided not to change the date format after all but I'm leaving this code here
// in case we need it later. Ryan
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//
// Attribute startDateAttr = task.getAttribute("startDate");
// Date startDate = (new CalendarDate(startDateAttr.getValue(),"/")).getDate();
// startDateAttr.setValue(sdf.format(startDate));
//
// Attribute endDateAttr = task.getAttribute("endDate");
// if (endDateAttr != null) {
// Date endDate = (new CalendarDate(endDateAttr.getValue(),"/")).getDate();
// endDateAttr.setValue(sdf.format(endDate));
// }
Attribute parentAttr = task.getAttribute("parent");
if ((parentAttr == null) || (parentAttr.getValue() == "")) {
// no parent, do nothing here
}
else {
// put the task under the parent task
String parentId = parentAttr.getValue();
for (int k = 0; k < tasks.size(); k++) {
Element potentialParent = tasks.get(k);
if(parentId.equals(potentialParent.getAttribute("id").getValue())) {
// found parent, put self under it
task.removeAttribute(parentAttr);
task.detach();
potentialParent.appendChild(task);
}
}
}
}
doc.setDocType(getCurrentDocType());
FileStorage.saveDocument(doc,filePath);
}
}
示例3: XomReader
import nu.xom.Document; //導入方法依賴的package包/類
public XomReader(final Document document) {
super(document.getRootElement());
}