当前位置: 首页>>代码示例>>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;未经允许,请勿转载。