當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.getRootElement方法代碼示例

本文整理匯總了Java中org.dom4j.Document.getRootElement方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.getRootElement方法的具體用法?Java Document.getRootElement怎麽用?Java Document.getRootElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.Document的用法示例。


在下文中一共展示了Document.getRootElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Dom2Map

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 解析XML並將其節點元素壓入Dto返回(基於節點值形式的XML格式) 應用於複雜對象
 * 
 * @param pStrXml 待解析的XML字符串
 * @return outDto 返回Dto
 */

public static Map Dom2Map(Document doc) {
	Map map = new HashMap();
	if (doc == null)
		return map;
	Element root = doc.getRootElement();
	for (Iterator iterator = root.elementIterator(); iterator.hasNext();) {
		Element e = (Element) iterator.next();
		// System.out.println(e.getName());
		List list = e.elements();
		if (list.size() > 0) {
			map.put(e.getName(), Dom2Map(e));
		} else
			map.put(e.getName(), e.getText());
	}
	return map;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:24,代碼來源:XmlUtil.java

示例2: parseDto2XmlHasHead

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 將Dto轉換為符合XML標準規範格式的字符串(基於節點值形式)
 * 
 * @param dto 傳入的Dto對象
 * @param pRootNodeName 根結點名
 * @return string 返回XML格式字符串
 */
public static final String parseDto2XmlHasHead(Map map, String pRootNodeName) {
	Document document = DocumentHelper.createDocument();
	// 增加一個根元素節點
	document.addElement(pRootNodeName);
	Element root = document.getRootElement();
	Iterator keyIterator = map.keySet().iterator();
	while (keyIterator.hasNext()) {
		String key = (String) keyIterator.next();
		String value = (String) map.get(key);
		Element leaf = root.addElement(key);
		leaf.setText(value);
	}
	// 將XML的頭聲明信息截去
	// String outXml = document.asXML().substring(39);
	String outXml = document.asXML();
	return outXml;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:25,代碼來源:XmlUtil.java

示例3: readDocument

import org.dom4j.Document; //導入方法依賴的package包/類
private Document readDocument(String path,String name, int age) throws DocumentException{
	SAXReader reader=new SAXReader();
	Document document=reader.read(path);
	Element root=document.getRootElement();
	List listOfTextView=document.selectNodes("view/body/form/textView");
	for(Iterator<Element> i=listOfTextView.listIterator();i.hasNext();){
		Element textView=i.next();
		if(textView.selectSingleNode("name").getText().equals("userName")){
			textView.selectSingleNode("value").setText(name);
		}
		if(textView.selectSingleNode("name").getText().equals("userAge")){
			textView.selectSingleNode("value").setText(""+age);
		}
	}
	System.out.println(document);
	return document;
}
 
開發者ID:Hang-Hu,項目名稱:SimpleController,代碼行數:18,代碼來源:XmlGenerator.java

示例4: parseXml2Map

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 解析XML並將其節點元素壓入Dto返回(基於節點值形式的XML格式)
 * 
 * @param pStrXml 待解析的XML字符串
 * @param pXPath 節點路徑(例如:"//paralist/row" 則表示根節點paralist下的row節點的xPath路徑)
 * @return outDto 返回Dto
 */
public static final Map parseXml2Map(String pStrXml, String pXPath) {
	Map map = new HashMap();
	String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	Document document = null;
	try {
		if (pStrXml.indexOf("<?xml") < 0)
			pStrXml = strTitle + pStrXml;
		document = DocumentHelper.parseText(pStrXml);
	} catch (DocumentException e) {
		log.error("==開發人員請注意:==\n將XML格式的字符串轉換為XML DOM對象時發生錯誤啦!" + "\n詳細錯誤信息如下:", e);
	}
	// 獲取根節點
	Element elNode = document.getRootElement();
	// 遍曆節點屬性值將其壓入Dto
	for (Iterator it = elNode.elementIterator(); it.hasNext();) {
		Element leaf = (Element) it.next();
		map.put(leaf.getName().toLowerCase(), leaf.getData());
	}
	return map;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:28,代碼來源:XmlUtil.java

示例5: parseInitData

import org.dom4j.Document; //導入方法依賴的package包/類
private Map<String, String> parseInitData(String data) {
    try {
        Map<String, String> ussData = new HashMap<>();
        Document document = DocumentHelper.parseText(data);
        Element root = document.getRootElement();
        Iterator iter = root.elementIterator();
        while (iter.hasNext()) {
            Element ele = (Element) iter.next();
            log.debug("name:" + ele.getName() + " value:" + ele.getStringValue());
            ussData.put(ele.getName(), ele.getStringValue());
        }

        // 隨機device id
        String deviceID = "e";
        for (int i = 0; i < 3; i++) {
            int randomNum = ThreadLocalRandom.current().nextInt(10000, 99999);
            deviceID += randomNum;
        }
        ussData.put("deviceID", deviceID);
        return ussData;
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:ingbyr,項目名稱:WechatBot,代碼行數:26,代碼來源:WechatBot.java

示例6: removeOAISetSpecDefinition

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 *  Removes the given OAI set definition from the ListSets config XML file and writes it to disc.
 *
 * @param  setsConfigFile  The ListSets config file
 * @param  setSpec         The set to remove
 * @return                 True if the set existed and was removed
 * @exception  Exception   If error
 */
public static boolean removeOAISetSpecDefinition(File setsConfigFile, String setSpec) throws Exception {
	Document document = null;
	if (setsConfigFile == null || !setsConfigFile.exists())
		return false;

	// Create the XML DOM
	if (setsConfigFile.exists()) {
		SAXReader reader = new SAXReader();
		document = reader.read(setsConfigFile);
	}

	Element root = document.getRootElement();
	if (!root.getName().equals("ListSets"))
		throw new Exception("OAI Sets XML is incorrect. Root node is not 'ListSets'");

	// Remove the previous set definition, if present
	String xPath = "set[setSpec=\"" + setSpec + "\"]";
	Element prevSet = (Element) root.selectSingleNode(xPath);
	if (prevSet == null)
		return false;
	root.remove(prevSet);

	// Write the XML to disc
	OutputFormat format = OutputFormat.createPrettyPrint();
	XMLWriter writer = new XMLWriter(new FileWriter(setsConfigFile), format);
	writer.write(document);
	writer.close();

	return true;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:39,代碼來源:OAISetsXMLConfigManager.java

示例7: getAssetDatas

import org.dom4j.Document; //導入方法依賴的package包/類
public static List<PageData> getAssetDatas(String xmlStr) throws Exception {
		Document document = DocumentHelper.parseText(xmlStr);
		List<PageData> res = null;
		if(null != document){
			res = new ArrayList<PageData>();
			//獲取文檔的根節點
			Element root = document.getRootElement();
			//取得某個節點的子節點
			Element element_sentence_list = root.element("ContentList");
			//取得某節點下所有名為“Program”的子節點,並進行遍曆
			List nodes = element_sentence_list.elements("Program");
			for (Iterator it = nodes.iterator(); it.hasNext();) {
				PageData pd_tmp = new PageData();
				Element elm = (Element) it.next();
				pd_tmp.put("name", elm.attribute("name").getText());
				pd_tmp.put("resourceCode", elm.attribute("contentID").getText());
				//取得某節點下所有名為“Series”的子節點,並進行遍曆
				List nodes1 = elm.elements("PictureList");
				for (Iterator it1 = nodes1.iterator(); it1.hasNext();) {
					Element elm1 = (Element) it1.next();
					List nodes2 = elm1.elements("Picture"); 
					for (Iterator it2 = nodes2.iterator(); it2.hasNext();) {
						Element elm2 = (Element) it2.next();
						pd_tmp.put("picFileURL", elm2.attribute("fileURL").getText());
//						System.out.println(elm.attribute("contentId").getText() + "-" + elm.attribute("name").getText() + "-" + elm2.attribute("fileURL").getText());
						res.add(pd_tmp);
					}
					break;
				}
			}
		}
		return res;
	}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:34,代碼來源:XmlUtils.java

示例8: parse

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * @param xml xml description
 * @throws DocumentException 
 */
public static OozieGraph parse(String xml) throws DocumentException {
	OozieGraph graph = new OozieGraph();
	Document doc =DocumentHelper.parseText(xml);
	Element root = doc.getRootElement();
	// parse widgets
	List<Element> nodes = root.elements("widget");
	for( Element node: nodes){
		String type = node.attributeValue("type");
		if (type.equals("dataset")) {
			OozieDatasetNode odn = parseDatasetNode(node);
			graph.addDatasetNode(odn);
		} else if(type.equals("program")){
			OozieProgramNode opn = parseProgramNode(node);
			graph.addProgramNode(opn);
			graph.addActiveNode(opn.getId());
		}

	}

	// parse edges
	List<Element> enodes = root.elements("edge");
	for(Element elem: enodes){
		OozieEdge edge = parseOozieEdge( elem);
		if (edge != null)
			graph.addEdge(edge);
	}

	return graph;
}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:34,代碼來源:OozieGraphXMLParser.java

示例9: contain

import org.dom4j.Document; //導入方法依賴的package包/類
public boolean contain(String path, String xml) {
	try{
		Document doc=DocumentHelper.parseText(xml);
		Element element=doc.getRootElement();
		for(Object obj:element.elements()){
			if(!(obj instanceof Element)){
				continue;
			}
			Element ele=(Element)obj;
			String name=ele.getName();
			boolean match=false;
			if(name.equals("import-variable-library")){
				match=true;
			}else if(name.equals("import-constant-library")){
				match=true;
			}else if(name.equals("import-action-library")){
				match=true;
			}else if(name.equals("import-parameter-library")){
				match=true;
			}
			if(!match){
				continue;
			}
			String filePath=ele.attributeValue("path");
			if(filePath.endsWith(path)){
				return true;
			}
		}
		return false;
	}catch(Exception ex){
		throw new RuleException(ex);
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:34,代碼來源:FlowDefinitionReferenceUpdater.java

示例10: addMultiDexMetaData

import org.dom4j.Document; //導入方法依賴的package包/類
private static void addMultiDexMetaData(Document document) {
    // Write meta-data information
    Element root = document.getRootElement();// Get the root node
    Element applicationElement = root.element("application");

    Element metaData = applicationElement.addElement("meta-data");
    metaData.addAttribute("android:name", "multidex_enable");
    metaData.addAttribute("android:value", "true");
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:10,代碼來源:ManifestFileUtils.java

示例11: ConfigurationWrapper

import org.dom4j.Document; //導入方法依賴的package包/類
private ConfigurationWrapper() {

        try {
            File configFile = getConfigFile();
            SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(configFile);
            rootElement = document.getRootElement();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:Shiroukoji,項目名稱:FH-Manager,代碼行數:12,代碼來源:ConfigurationWrapper.java

示例12: readConfiguration

import org.dom4j.Document; //導入方法依賴的package包/類
public MappingDescriptor readConfiguration(String fileAddress){
    MappingDescriptor mappingDescriptor=new MappingDescriptor();
    Document document = readXml(fileAddress);
    Element rootElement=document.getRootElement();
    for(Iterator<Element> i=rootElement.elementIterator("class");i.hasNext();){
        Element classElement =  i.next();
        MappingDescriptor.ClassDescriptor classDescriptor=new MappingDescriptor.ClassDescriptor();
        classDescriptor.setClassAttribute(readClassAttribute(classElement.attributes()));
        classDescriptor.setId(readId(classElement.element("id")));
        classDescriptor.setProperties(readProperties(classElement.elements("property")));
        mappingDescriptor.setClassDescriptor(classDescriptor);
    }
    return mappingDescriptor;
}
 
開發者ID:Hang-Hu,項目名稱:SimpleController,代碼行數:15,代碼來源:DatabaseXmlReader.java

示例13: parse

import org.dom4j.Document; //導入方法依賴的package包/類
/**
	 * 解析測試套件配置文件
	 * @param suiteInputStream 配置文件輸入流
	 * @return 測試套件對象
	 * @throws DocumentException
	 */
	public Suite parse(InputStream suiteInputStream) throws DocumentException
	{
		SAXReader reader = new SAXReader();
		reader.setEncoding("utf-8");
		
		Document document = reader.read(suiteInputStream);
		
		simpleNamespaceContext.addNamespace("ns", NS_URI);
		
		XPath xpath = new DefaultXPath("/ns:suite");
		xpath.setNamespaceContext(simpleNamespaceContext);
		Element suiteEle = (Element) xpath.selectSingleNode(document);
		if (suiteEle == null)
		{
			suiteEle = document.getRootElement();
//			throw new RuntimeException("Can not found suite config.");
		}
		
		Suite suite = new Suite();
		String xmlConfPath = suiteEle.attributeValue("pageConfig");
		String pagePackage = suiteEle.attributeValue("pagePackage", "");
		String rows = suiteEle.attributeValue("rows", "1");
		String lackLines = suiteEle.attributeValue("lackLines", "nearby");
		String errorLines = suiteEle.attributeValue("errorLines", "stop");
		String afterSleep = suiteEle.attributeValue("afterSleep", "0");
		
		suite.setXmlConfPath(xmlConfPath);
		suite.setPagePackage(pagePackage);
		suite.setRows(rows);
		suite.setLackLines(lackLines);
		suite.setErrorLines(errorLines);
		suite.setAfterSleep(Long.parseLong(afterSleep));
		
		pagesParse(document, suite);
		
		return suite;
	}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.suite.runner,代碼行數:44,代碼來源:XmlSuiteParser.java

示例14: delocalizeXml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 *  Insert nameSpaceInformation into the root element
 *
 * @param  doc              Description of the Parameter
 * @param  rootElementName  Description of the Parameter
 * @param  nameSpaceInfo    Description of the Parameter
 * @return                  Description of the Return Value
 */
public static Document delocalizeXml(Document doc, String rootElementName, String nameSpaceInfo) {
	Element root = doc.getRootElement();
	String rootName = root.getName();
	String namespaceXml = delocalizeDocStr(doc.asXML(), rootElementName, nameSpaceInfo);
	try {
		return getXmlDocument(namespaceXml);
	} catch (Exception e) {
		prtln("unable to delocalizeItemRecordDoc(): " + e);
	}
	return null;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:20,代碼來源:Dom4jUtils.java

示例15: parseXml

import org.dom4j.Document; //導入方法依賴的package包/類
protected Element parseXml(InputStream stream){
	SAXReader reader=new SAXReader();
	Document document;
	try {
		document = reader.read(stream);
		Element root=document.getRootElement();
		return root;
	} catch (DocumentException e) {
		throw new RuleException(e);
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:12,代碼來源:CommonServletHandler.java


注:本文中的org.dom4j.Document.getRootElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。