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


Java Document.addElement方法代碼示例

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


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

示例1: parseMap2Xml

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

示例2: parseDto2Xml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 將Dto轉換為符合XML標準規範格式的字符串(基於節點值形式)
 * 
 * @param dto 傳入的Dto對象
 * @param pRootNodeName 根結點名
 * @return string 返回XML格式字符串
 */
public static final String parseDto2Xml(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);
	return outXml;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:24,代碼來源:XmlUtil.java

示例3: parseMap2Xml

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

示例4: parseList2Xml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 將List數據類型轉換為符合XML格式規範的字符串(基於節點屬性值的方式)
 * 
 * @param pList 傳入的List數據(List對象可以是Dto、VO、Domain的屬性集)
 * @param pRootNodeName 根節點名稱
 * @param pFirstNodeName 行節點名稱
 * @return string 返回XML格式字符串
 */
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
    Document document = DocumentHelper.createDocument();
    Element elRoot = document.addElement(pRootNodeName);
    for (int i = 0; i < pList.size(); i++) {
        Map map = (Map)pList.get(i);
        Element elRow = elRoot.addElement(pFirstNodeName);
        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry)it.next();
            elRow.addAttribute((String)entry.getKey(), String.valueOf(entry.getValue()));
        }
    }
    String outXml = document.asXML().substring(39);
    return outXml;
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:24,代碼來源:XmlUtil.java

示例5: parseList2Xml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 將List數據類型轉換為符合XML格式規範的字符串(基於節點屬性值的方式)
 * 
 * @param pList 傳入的List數據(List對象可以是Dto、VO、Domain的屬性集)
 * @param pRootNodeName 根節點名稱
 * @param pFirstNodeName 行節點名稱
 * @return string 返回XML格式字符串
 */
public static final String parseList2Xml(List pList, String pRootNodeName, String pFirstNodeName) {
	Document document = DocumentHelper.createDocument();
	Element elRoot = document.addElement(pRootNodeName);
	for (int i = 0; i < pList.size(); i++) {
		Map map = (Map) pList.get(i);
		Element elRow = elRoot.addElement(pFirstNodeName);
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			elRow.addAttribute((String) entry.getKey(), String.valueOf(entry.getValue()));
		}
	}
	String outXml = document.asXML().substring(39);
	return outXml;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:24,代碼來源:XmlUtil.java

示例6: 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:youngMen1,項目名稱:JAVA-,代碼行數:25,代碼來源:XmlUtil.java

示例7: emitValue

import org.dom4j.Document; //導入方法依賴的package包/類
private void emitValue(String path, String content){
    
    Document document = DocumentHelper.createDocument();
    Element eleRoot = document.addElement("msg");
    
    Element elePath = eleRoot.addElement("path");
    Element eleContent = eleRoot.addElement("value");
    
    elePath.setText(path);
    eleContent.setText(content);

    String msg = document.asXML();
    
    if(handler != null){
    	MsgReceiveEvent event = new MsgReceiveEvent(this, msg);
    	handler.receiveMsgEvent(event);
    }
}
 
開發者ID:IoTKETI,項目名稱:IPE-LWM2M,代碼行數:19,代碼來源:SimpleLwm2mServer.java

示例8: parseList2XmlBasedNode

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * 將List數據類型轉換為符合XML格式規範的字符串(基於節點值的方式)
 * 
 * @param pList 傳入的List數據(List對象可以是Dto、VO、Domain的屬性集)
 * @param pRootNodeName 根節點名稱
 * @param pFirstNodeName 行節點名稱
 * @return string 返回XML格式字符串
 */
public static final String parseList2XmlBasedNode(List pList, String pRootNodeName, String pFirstNodeName) {
	Document document = DocumentHelper.createDocument();
	Element output = document.addElement(pRootNodeName);
	for (int i = 0; i < pList.size(); i++) {
		Map map = (Map) pList.get(i);
		Element elRow = output.addElement(pFirstNodeName);
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			Element leaf = elRow.addElement((String) entry.getKey());
			leaf.setText(String.valueOf(entry.getValue()));
		}
	}
	String outXml = document.asXML().substring(39);
	return outXml;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:25,代碼來源:XmlUtil.java

示例9: toDsml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * Converts this Batch Request to its XML representation in the DSMLv2 format.
 * 
 * @return the XML representation in DSMLv2 format
 */
public String toDsml()
{
    Document document = DocumentHelper.createDocument();
    Element element = document.addElement( "batchRequest" );

    // RequestID
    if ( requestID != 0 )
    {
        element.addAttribute( "requestID", Integer.toString( requestID ) );
    }

    // ResponseOrder
    if ( responseOrder == ResponseOrder.UNORDERED )
    {
        element.addAttribute( "responseOrder", "unordered" );
    }

    // Processing
    if ( processing == Processing.PARALLEL )
    {
        element.addAttribute( "processing", "parallel" );
    }

    // On Error
    if ( onError == OnError.RESUME )
    {
        element.addAttribute( "onError", "resume" );
    }

    // Requests
    for ( DsmlDecorator<? extends Request> request : requests )
    {
        request.toDsml( element );
    }

    return ParserUtils.styleDocument( document ).asXML();
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:43,代碼來源:BatchRequestDsml.java

示例10: toDsml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * Converts this Batch Response to its XML representation in the DSMLv2 format.
 * 
 * @param prettyPrint if true, formats the document for pretty printing
 * @return the XML representation in DSMLv2 format
 */
public String toDsml( boolean prettyPrint )
{
    Document document = DocumentHelper.createDocument();
    Element element = document.addElement( "batchResponse" );

    element.add( ParserUtils.DSML_NAMESPACE );
    element.add( ParserUtils.XSD_NAMESPACE );
    element.add( ParserUtils.XSI_NAMESPACE );

    // RequestID
    if ( requestID != 0 )
    {
        element.addAttribute( "requestID", Integer.toString( requestID ) );
    }

    for ( DsmlDecorator<? extends Response> response : responses )
    {
        response.toDsml( element );
    }

    if ( prettyPrint )
    {
        document = ParserUtils.styleDocument( document );
    }
    
    return document.asXML();
}
 
開發者ID:apache,項目名稱:directory-ldap-api,代碼行數:34,代碼來源:BatchResponseDsml.java

示例11: saveXml

import org.dom4j.Document; //導入方法依賴的package包/類
public void saveXml(Document document, Session session, Properties parameters) throws Exception {
	try {
		beginTransaction();

        Element root = document.addElement("permissions");
        root.addAttribute("created", new Date().toString());

        document.addDocType("permissions", "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/Permissions.dtd");
        
		for (Roles role: RolesDAO.getInstance().findAll(getHibSession(), Order.asc("abbv"))) {
			Element r = root.addElement("role");
			r.addAttribute("reference", role.getReference());
			r.addAttribute("name", role.getAbbv());
			r.addAttribute("manager", role.isManager() ? "true" : "false");
			r.addAttribute("enabled", role.isEnabled() ? "true" : "false");
			r.addAttribute("instructor", role.isInstructor() ? "true" : "false");
			for (Right right: Right.values()) {
				if (role.hasRight(right))
					r.addElement("right").setText(right.name());
			}
		}

        commitTransaction();
    } catch (Exception e) {
        fatal("Exception: "+e.getMessage(),e);
        rollbackTransaction();
    }
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:29,代碼來源:PermissionsExport.java

示例12: createLuceneQueryElement

import org.dom4j.Document; //導入方法依賴的package包/類
private static Element createLuceneQueryElement(String query) throws Exception {
	if (query == null || query.trim().length() == 0)
		throw new Exception("query must not be empty or null");

	Document document = DocumentHelper.createDocument();
	Element luceneQuery = document.addElement("luceneQuery");
	luceneQuery.addText(query);
	return luceneQuery;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:10,代碼來源:OAISetsXMLConfigManager.java

示例13: generateArclibXml

import org.dom4j.Document; //導入方法依賴的package包/類
/**
 * Generates ARCLib XML from SIP using the SIP profile
 *
 * @param sipPath      path to the SIP package
 * @param sipProfileId id of the SIP profile
 * @return ARCLib XML
 * @throws IOException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws TransformerException
 */
public String generateArclibXml(String sipPath, String sipProfileId)
        throws ParserConfigurationException, TransformerException, SAXException, IOException {
    log.info("Generating ARCLib XML for SIP at path " + sipPath + " using SIP profile with ID " + sipProfileId + ".");

    SipProfile sipProfile = store.find(sipProfileId);
    notNull(sipProfile, () -> new MissingObject(SipProfile.class, sipProfileId));

    ArclibXmlValidator.validateWithXMLSchema(
            new ByteArrayInputStream(sipProfile.getXml().getBytes(StandardCharsets.UTF_8.name())),
            new InputStream[]{sipProfileSchema.getInputStream()});

    String sipProfileXml = sipProfile.getXml();
    notNull(sipProfileXml, () -> new InvalidAttribute(sipProfile, "xml", null));

    Document arclibXmlDoc = DocumentHelper.createDocument();
    arclibXmlDoc.addElement(new QName(ROOT, Namespace.get("METS", uris.get("METS"))));

    NodeList mappingNodes = XPathUtils.findWithXPath(stringToInputStream(sipProfileXml), MAPPING_ELEMENTS_XPATH);
    for (int i = 0; i < mappingNodes.getLength(); i++) {
        Set<Utils.Pair<String, String>> nodesToCreate = nodesToCreateByMapping((Element) mappingNodes.item(i), sipPath);

        XmlBuilder xmlBuilder = new XmlBuilder(uris);
        for (Utils.Pair<String, String> xPathToValue : nodesToCreate) {
            xmlBuilder.addNode(arclibXmlDoc, xPathToValue.getL(), xPathToValue.getR(), uris.get("ARCLIB"));
        }
    }

    String arclibXml = arclibXmlDoc.asXML().replace("&lt;", "<").replace("&gt;", ">");
    log.info("Generated ARCLib XLM: \n" + arclibXml);

    return arclibXml;
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:44,代碼來源:ArclibXmlGenerator.java

示例14: writeXml

import org.dom4j.Document; //導入方法依賴的package包/類
private void writeXml(List<JSONArray> list) throws Exception {
	File file = new File(SAVE_PATH);
	if (file.exists())
		file.delete();

	// 生成一個文檔
	Document document = DocumentHelper.createDocument();
	Element root = document.addElement("root");
	for (JSONArray jsonArray : list) {
		for (Object object : jsonArray) {
			JSONObject json = (JSONObject) object;
			System.out.println(json);
			Element element = root.addElement("branch");
			// 為cdr設置屬性名和屬性值
			element.addAttribute("branchId", json.getString("prcptcd").trim());// 支行行號
			element.addAttribute("bankCode", json.getString("bankCode").trim());// 銀行類型
			element.addAttribute("cityCode", json.getString("cityCode").trim());// 城市代碼
			element.addAttribute("branchName", json.getString("brabank_name").trim());// 支行名稱
		}
	}
	OutputFormat format = OutputFormat.createPrettyPrint();
	format.setEncoding("UTF-8");
	XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(new File(SAVE_PATH)), "UTF-8"), format);
	// 寫入新文件
	writer.write(document);
	writer.flush();
	writer.close();
}
 
開發者ID:yi-jun,項目名稱:aaden-pay,代碼行數:29,代碼來源:LianlianBranchTest.java

示例15: saveXml

import org.dom4j.Document; //導入方法依賴的package包/類
@Override
public void saveXml(Document document, Session session, Properties parameters) throws Exception {
	try {
		beginTransaction();
		
		Element root = document.addElement("studentEnrollments");
        root.addAttribute("campus", session.getAcademicInitiative());
        root.addAttribute("year", session.getAcademicYear());
        root.addAttribute("term", session.getAcademicTerm());
        document.addDocType("studentEnrollments", "-//UniTime//UniTime Student Enrollments DTD/EN", "http://www.unitime.org/interface/StudentEnrollment.dtd");
        
        for (Student student: (List<Student>)getHibSession().createQuery(
        		"select s from Student s where s.session.uniqueId = :sessionId")
        		.setLong("sessionId", session.getUniqueId()).list()) {
        	if (student.getClassEnrollments().isEmpty()) continue;
        	Element studentEl = root.addElement("student");
        	studentEl.addAttribute("externalId",
        			student.getExternalUniqueId() == null || student.getExternalUniqueId().isEmpty() ? student.getUniqueId().toString() : student.getExternalUniqueId());
        	for (StudentClassEnrollment enrollment: student.getClassEnrollments()) {
        		Element classEl = studentEl.addElement("class");
        		Class_ clazz = enrollment.getClazz();
        		CourseOffering course = enrollment.getCourseOffering();
        		String extId = (course == null ? clazz.getExternalUniqueId() : clazz.getExternalId(course));
        		if (extId != null && !extId.isEmpty())
        			classEl.addAttribute("externalId", extId);
        		classEl.addAttribute("id", clazz.getUniqueId().toString());
        		if (course != null) {
        			if (course.getExternalUniqueId() != null && !course.getExternalUniqueId().isEmpty())
        				classEl.addAttribute("courseId", course.getExternalUniqueId());
        			classEl.addAttribute("subject", course.getSubjectAreaAbbv());
        			classEl.addAttribute("courseNbr", course.getCourseNbr());
        		}
        		classEl.addAttribute("type", clazz.getSchedulingSubpart().getItypeDesc().trim());
        		classEl.addAttribute("suffix", getClassSuffix(clazz));
        	}
        }
        
           commitTransaction();
       } catch (Exception e) {
           fatal("Exception: "+e.getMessage(),e);
           rollbackTransaction();
	}
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:44,代碼來源:StudentEnrollmentExport.java


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