本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
}
示例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;
}
示例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("<", "<").replace(">", ">");
log.info("Generated ARCLib XLM: \n" + arclibXml);
return arclibXml;
}
示例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();
}
示例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();
}
}