List of usage examples for org.dom4j Element elements
List<Element> elements();
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * delete the label of xml that is not use * * @param message//from w ww . ja v a 2 s . c o m * @return */ public static Map<String, Object> getMessage(String message) throws DocumentException { message = replaceWrongPart(message); Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); Element request = rootElement.element("request"); List elements = request.elements(); Map<String, Object> result = new HashMap<>(); for (Object element : elements) { Element subElement = (Element) element; if (subElement.isTextOnly()) { result.put(subElement.getName(), subElement.getTextTrim()); } else { List<String> subList = new ArrayList<>(); List subEle = subElement.elements(); for (Object aSubEle : subEle) { Element itemElements = (Element) aSubEle; subList.add(itemElements.getTextTrim()); } result.put(subElement.getName(), subList); } } return result; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
public static Map<String, Object> getMessageReceiveSample(String message) throws DocumentException { message = replaceWrongPart(message); Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); Element request = rootElement.element("request"); List elements = request.elements(); Map<String, Object> result = new HashMap<>(); for (Object element : elements) { Element subElement = (Element) element; String name = subElement.getName(); if (name.equalsIgnoreCase("item")) { List subElements = subElement.elements(); for (Object subEle : subElements) { Element grantSubElement = (Element) subEle; result.put(grantSubElement.getName(), grantSubElement.getTextTrim()); }/*w ww . j av a 2 s. c om*/ } else if (subElement.isTextOnly()) { result.put(name, subElement.getTextTrim()); } } return result; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
public static List<Map<String, Object>> getMessageReceiveSampleContainItems(String message) throws DocumentException { message = replaceWrongPart(message); Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); Element request = rootElement.element("request"); Element items = request.element("items"); List elements = items.elements(); List<Map<String, Object>> resultList = new ArrayList<>(); for (Object element : elements) { Map<String, Object> result = new HashMap<>(); Element subElement = (Element) element; String name = subElement.getName(); if (name.equalsIgnoreCase("item")) { List subElements = subElement.elements(); for (Object subEle : subElements) { Element grantSubElement = (Element) subEle; result.put(grantSubElement.getName(), grantSubElement.getTextTrim()); }//from w w w . java2 s.c om } else if (subElement.isTextOnly()) { result.put(name, subElement.getTextTrim()); } resultList.add(result); } return resultList; }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * delete the label of xml that is not use * * @param message//from w w w . j a va 2s . co m * @return */ public static Map<String, Object> getMessageContainsMap(String message) throws DocumentException { message = replaceWrongPart(message); Document document = DocumentHelper.parseText(message); Element rootElement = document.getRootElement(); Element request = rootElement.element("request"); List elements = request.elements(); Map<String, Object> result = new HashMap<>(); for (Object element : elements) { Element subElement = (Element) element; if (subElement.isTextOnly()) { result.put(subElement.getName(), subElement.getTextTrim()); } else { List<Map<String, String>> subList = new ArrayList<>(); List subEle = subElement.elements(); for (Object aSubEle : subEle) { Element itemElements = (Element) aSubEle; Map<String, String> subMap = new HashMap<>(); List grandSubElements = itemElements.elements(); for (Object grandSubElement : grandSubElements) { Element grandItemElements = (Element) grandSubElement; subMap.put(grandItemElements.getName().trim(), grandItemElements.getTextTrim()); } subList.add(subMap); } result.put(subElement.getName(), subList); } } return result; }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ???//from w w w . j ava2s . c om * @param element * @return */ public List<Object> elementList(Element element) { @SuppressWarnings("unchecked") List<Object> list = element.elements(); return list; }
From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java
License:Open Source License
private void parseEvent(Element element) { String type = element.attributeValue("type"); List listeners = element.elements(); String[] listenerClasses = new String[listeners.size()]; for (int i = 0; i < listeners.size(); i++) { listenerClasses[i] = ((Element) listeners.get(i)).attributeValue("class"); }//from w ww. j ava2 s .co m log.debug("Event listeners: " + type + "=" + StringHelper.toString(listenerClasses)); setListeners(type, listenerClasses); }
From source file:com.iisigroup.cap.utils.CapXmlUtil.java
License:Open Source License
@SuppressWarnings("unchecked") private static JSONObject travelXML(Element el) { JSONObject json = new JSONObject(); String nodeName = el.getName(); if (el.elements().isEmpty()) { putJSONValue(json, nodeName, el.getTextTrim()); } else {//from w w w . j av a2 s . c o m JSONObject json2 = new JSONObject(); for (Element el2 : (List<Element>) el.elements()) { putJSONValue(json2, el2.getName(), travelXML(el2).get(el2.getName())); } putJSONValue(json, nodeName, json2); } return json; }
From source file:com.ischool.weixin.tool.MessageUtil.java
License:Open Source License
public static Map<String, String> parseXml(HttpServletRequest request) throws Exception { // ?HashMap// w w w.j av a 2s . com Map<String, String> map = new HashMap<String, String>(); // request?? InputStream inputStream = request.getInputStream(); // ?? SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); // xml Element root = document.getRootElement(); // ? @SuppressWarnings("unchecked") List<Element> elementList = root.elements(); // ??? for (Element e : elementList) { map.put(e.getName(), e.getText()); } // ? inputStream.close(); inputStream = null; return map; }
From source file:com.jeeframework.util.xml.XMLProperties.java
License:Open Source License
private List<String> getChildPropertyNamesFor(Element parent, String parentName) { List<String> result = new ArrayList<String>(); for (Element child : (Collection<Element>) parent.elements()) { String childName = new StringBuilder(parentName).append(parentName.isEmpty() ? "" : ".") .append(child.getName()).toString(); if (!result.contains(childName)) { result.add(childName);/* w w w . jav a 2 s .c o m*/ result.addAll(getChildPropertyNamesFor(child, childName)); } } return result; }
From source file:com.jeeframework.util.xml.XMLProperties.java
License:Open Source License
/** * Return all children property names of a parent property as a String array, * or an empty array if the if there are no children. For example, given * the properties <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, and <tt>X.Y.C</tt>, then * the child properties of <tt>X.Y</tt> are <tt>A</tt>, <tt>B</tt>, and * <tt>C</tt>./* www.j a v a 2 s. c o m*/ * * @param parent the name of the parent property. * @return all child property values for the given parent. */ public String[] getChildrenProperties(String parent) { String[] propName = parsePropertyName(parent); // Search for this property by traversing down the XML hierarchy. Element element = document.getRootElement(); for (String aPropName : propName) { element = element.element(aPropName); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return empty array. return new String[] {}; } } // We found matching property, return names of children. List children = element.elements(); int childCount = children.size(); String[] childrenNames = new String[childCount]; for (int i = 0; i < childCount; i++) { childrenNames[i] = ((Element) children.get(i)).getName(); } return childrenNames; }