use of org.dom4j.io.SAXReader in project fmv by f-agu.
the class Project method load.
/**
* @throws LoadException
*/
public void load() throws LoadException {
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
try {
Document document = reader.read(getSaveFile());
Element root = document.getRootElement();
loadMain(root);
loadSources(root);
loadExtensions(root);
loadProperties(root);
loadUndeleteFile(root);
loadOutputInfos(root);
loadExecutables(root);
} catch (DocumentException e) {
throw new LoadException(e);
}
modified = false;
fileCache.clean();
fileCache.start();
}
use of org.dom4j.io.SAXReader in project sagacity-sqltoy by chenrenfei.
the class XMLUtil method getXPathElement.
/**
* @todo 根据qName 获取节点对象
* @param xmlFile
* @param qName
* @return
* @throws Exception
*/
public static Object getXPathElement(File xmlFile, String qName) throws Exception {
SAXReader saxReader = new SAXReader();
InputStream is = new FileInputStream(xmlFile);
org.dom4j.Document doc = saxReader.read(is);
return doc.getRootElement().selectObject(qName);
}
use of org.dom4j.io.SAXReader in project notes by KevinBlandy.
the class Dom4jDemo method getLast.
/**
* ��ȡָ��Ԫ�ص����һ��ֵ(name)
*/
public static void getLast() throws Exception {
// 1,��������������
SAXReader reader = new SAXReader();
// 2,����xml�ļ�
Document document = reader.read(file);
// 3,��ȡ���ڵ�
Element root = document.getRootElement();
// 3,�Ķ����е�p�ڵ�
List<Element> list = root.elements("p");
// 3,��ȡ���һ��p�ڵ�
Element ele = list.get(list.size() - 1);
// ,��ȡ���һ��p�ڵ��,name�ڵ�
Element name = ele.element("name");
// 3,��ȡ���һ��name�ڵ��ֵ
System.out.println(name.getText());
}
use of org.dom4j.io.SAXReader in project notes by KevinBlandy.
the class Dom4jDemo method add.
/**
* ��ӽڵ����(���һ��gender��ǩ)
*/
public static void add() throws Exception {
// ǰ�漸���趼һ��.ʡ��ע����
Document document = new SAXReader().read(file);
// ��ȡ���ڵ�
Element element = document.getRootElement();
// ��ȡҪ��ӵĽڵ����,,Ҳ���ǵڶ���p�ڵ�
Element ele = (Element) element.elements("p").get(1);
// ���һ������gender���ӱ�ǩ
Element newEle = ele.addElement("gender");
// Ϊ�±�ǩ����ı�
newEle.setText("��");
/**
*ע��,��д������,��ɾ����һ��Ҫ�ǵû�д*
*/
// �����ı���ʽ,��������
OutputFormat format = OutputFormat.createPrettyPrint();
// ����������
XMLWriter wr = new XMLWriter(new FileOutputStream(file), format);
// ���ڴ��е�Document��д���ļ���
wr.write(document);
// �ر���Դ
wr.close();
}
use of org.dom4j.io.SAXReader in project notes by KevinBlandy.
the class Dom4jDemo method delete.
/**
* ɾ���ڵ�IJ���(ɾ������һ����ӵ�gender)
*/
public static void delete() throws Exception {
// ǰ�漸���趼һ��.ʡ��ע����
Document document = new SAXReader().read(file);
// ��ȡ���ڵ�
Element element = document.getRootElement();
// ��ȡ�ڶ���p�ڵ�
Element ele = (Element) element.elements("p").get(1);
// ��ȡҪɾ���Ľڵ�
Element gen = ele.element("gender");
// �ø��ڵ�ȥɾ��ָ���ڵ�
ele.remove(gen);
// �����
write(document, file);
}
Aggregations