本文整理汇总了Java中org.dom4j.DocumentHelper类的典型用法代码示例。如果您正苦于以下问题:Java DocumentHelper类的具体用法?Java DocumentHelper怎么用?Java DocumentHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentHelper类属于org.dom4j包,在下文中一共展示了DocumentHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldBuildDocumentFromSetOfXPaths
import org.dom4j.DocumentHelper; //导入依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPaths() throws XPathExpressionException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties.keySet())
.build(DocumentHelper.createDocument());
for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
XPath xpath = builtDocument.createXPath(xpathToValuePair.getKey());
if (null != namespaceContext) {
xpath.setNamespaceContext(new SimpleNamespaceContextWrapper(namespaceContext));
}
assertThat(xpath.evaluate(builtDocument)).isNotNull();
}
assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutXml());
}
示例2: parseDto2Xml
import org.dom4j.DocumentHelper; //导入依赖的package包/类
/**
* 将Dto转换为符合XML标准规范格式的字符串(基于节点值形式)
*
* @param map 传入的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.DocumentHelper; //导入依赖的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.DocumentHelper; //导入依赖的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: parseList2XmlBasedNode
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例6: MqResToDto
import org.dom4j.DocumentHelper; //导入依赖的package包/类
/**
* 将mq查询结果包装成list--dto的形式,dto内容为item中的内容
*
* @param recv
* @return
*/
public static Map MqResToDto(String recv) {
// System.out.println("####recv"+recv);
List res = new ArrayList();
Map map = new HashMap();
try {
Document doc = DocumentHelper.parseText(recv);
List list = doc.selectNodes("//item");
Iterator<DefaultElement> it = list.iterator();
while (it.hasNext()) {
Map elementdto = XmlUtil.Dom2Map(it.next());
res.add(elementdto);
}
map.put("resultList", res);// 放入结果集
/* 如果存在REC_MNT,说明是分页查询类,需要将总记录数返回 */
Node de = doc.selectSingleNode("//REC_MNT");
if (DataUtil.isNotEmpty(de)) {
map.put("countInteger", de.getText());
}
} catch (Exception e) {
logger.error("", e);
}
return map;
}
示例7: parseList2Xml
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例8: addItem
import org.dom4j.DocumentHelper; //导入依赖的package包/类
protected static void addItem(org.hibernate.Session hibSession, UserContext user, Long sessionId, Type type, Long... ids) {
StudentSectioningQueue q = new StudentSectioningQueue();
q.setTimeStamp(new Date());
q.setType(type.ordinal());
q.setSessionId(sessionId);
Document d = DocumentHelper.createDocument();
Element root = d.addElement("generic");
if (user != null) {
Element e = root.addElement("user");
e.addAttribute("id", user.getExternalUserId()).setText(user.getName());
}
if (ids != null && ids.length > 0) {
for (Long id: ids)
root.addElement("id").setText(id.toString());
}
q.setMessage(d);
hibSession.save(q);
}
示例9: parseXml2Map
import org.dom4j.DocumentHelper; //导入依赖的package包/类
/**
* 解析XML并将其节点元素压入Dto返回(基于节点值形式的XML格式)
*
* @param pStrXml 待解析的XML字符串
* @return outDto 返回Dto
*/
public static final Map parseXml2Map(String pStrXml) {
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;
}
示例10: parseDto2Xml
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例11: parseDto2XmlHasHead
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例12: parseMap2Xml
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例13: parseList2XmlBasedNode
import org.dom4j.DocumentHelper; //导入依赖的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;
}
示例14: emitValue
import org.dom4j.DocumentHelper; //导入依赖的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);
}
}
示例15: loadResourceSecurityConfigs
import org.dom4j.DocumentHelper; //导入依赖的package包/类
@Override
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
List<UserPermission> configs=new ArrayList<UserPermission>();
String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
Node rootNode=getRootNode();
Node fileNode = rootNode.getNode(filePath);
Property property = fileNode.getProperty(DATA);
Binary fileBinary = property.getBinary();
InputStream inputStream = fileBinary.getStream();
String content = IOUtils.toString(inputStream, "utf-8");
inputStream.close();
Document document = DocumentHelper.parseText(content);
Element rootElement = document.getRootElement();
for (Object obj : rootElement.elements()) {
if (!(obj instanceof Element)) {
continue;
}
Element element = (Element) obj;
if (!element.getName().equals("user-permission")) {
continue;
}
UserPermission userResource=new UserPermission();
userResource.setUsername(element.attributeValue("username"));
userResource.setProjectConfigs(parseProjectConfigs(element));
configs.add(userResource);
}
return configs;
}