Java Code Examples for org.dom4j.Element#attributes()
The following examples show how to use
org.dom4j.Element#attributes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManifestFileUtils.java From atlas with Apache License 2.0 | 6 votes |
public static String getVersionCode(File androidManifestFile) throws IOException, DocumentException { SAXReader reader = new SAXReader(); String versionCode = ""; if (androidManifestFile.exists()) { Document document = reader.read(androidManifestFile);// Read the XML file Element root = document.getRootElement();// Get the root node if ("manifest".equalsIgnoreCase(root.getName())) { List<Attribute> attributes = root.attributes(); for (Attribute attr : attributes) { if (StringUtils.equalsIgnoreCase(attr.getName(), "versionCode")) { versionCode = attr.getValue(); } } } } return versionCode; }
Example 2
Source File: XmlObjectReader.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
private void checkForIgnoredElements(final StringBuffer buf, final Element el) { if (processedElements.contains(el) == false) { buf.append("Ignored xml element: ").append(el.getPath()).append("\n"); } @SuppressWarnings("rawtypes") final List attributes = el.attributes(); if (attributes != null) { final Set<String> attributeSet = processedAttributes.get(el); for (final Object attr : attributes) { if (attributeSet == null || attributeSet.contains(((Attribute) attr).getName()) == false) { buf.append("Ignored xml attribute: ").append(((Attribute) attr).getPath()).append("\n"); } } } @SuppressWarnings("rawtypes") final List children = el.elements(); if (children != null) { for (final Object child : children) { checkForIgnoredElements(buf, (Element) child); } } }
Example 3
Source File: Metric.java From big-c with Apache License 2.0 | 6 votes |
public void Parse(Element node){ if(node.getName() != "METRIC"){ return; } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="TYPE"){ this.setType(attribute.getValue()); } if(attribute.getName()=="VAL"){ this.setValue(attribute.getValue()); } } }
Example 4
Source File: ManifestFileUtils.java From atlas with Apache License 2.0 | 6 votes |
/** * Update the plug-in's minSdkVersion and targetSdkVersion * * @param androidManifestFile * @throws IOException * @throws DocumentException */ public static String getVersionName(File androidManifestFile) throws IOException, DocumentException { SAXReader reader = new SAXReader(); String versionName = ""; if (androidManifestFile.exists()) { Document document = reader.read(androidManifestFile);// Read the XML file Element root = document.getRootElement();// Get the root node if ("manifest".equalsIgnoreCase(root.getName())) { List<Attribute> attributes = root.attributes(); for (Attribute attr : attributes) { if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) { versionName = attr.getValue(); } } } } return versionName; }
Example 5
Source File: VersionedXmlDoc.java From onedev with MIT License | 5 votes |
private void marshallElement(HierarchicalStreamWriter writer, Element element) { writer.startNode(element.getName()); for (Attribute attribute: (List<Attribute>)element.attributes()) writer.addAttribute(attribute.getName(), attribute.getValue()); if (element.getText().trim().length() != 0) writer.setValue(element.getText().trim()); for (Element child: (List<Element>)element.elements()) marshallElement(writer, child); writer.endNode(); }
Example 6
Source File: XMLDocUtil.java From boubei-tss with Apache License 2.0 | 5 votes |
/** * 将xml节点上各个属性的数据按 name/value 放入到Map中 * 格式如<row id="1" name="Jon"/> * @param dataNode * @return */ @SuppressWarnings("unchecked") public static Map<String, String> dataNode2Map(Element dataNode) { Map<String, String> attrsMap = new HashMap<String, String>(); if(dataNode != null){ List<AbstractAttribute> attributes = dataNode.attributes(); attributes = (List<AbstractAttribute>) EasyUtils.checkNull(attributes, new ArrayList<AbstractAttribute>()); for (AbstractAttribute attr : attributes) { attrsMap.put(attr.getName(), attr.getValue()); } } return attrsMap; }
Example 7
Source File: XMLElementRTPFLOWParser.java From mts with GNU General Public License v3.0 | 5 votes |
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> result = new LinkedList(); //do classic replacement of attribute and save it in result Element newElement = element.createCopy(); result.add(newElement); List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { if (!attribute.getName().equalsIgnoreCase("timestamp") && !attribute.getName().equalsIgnoreCase("seqnum") && !attribute.getName().equalsIgnoreCase("deltaTime") && !attribute.getName().equalsIgnoreCase("mark")) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() != 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } attribute.setValue(parsedValue.getFirst()); } } return result; }
Example 8
Source File: XMLTree.java From mts with GNU General Public License v3.0 | 5 votes |
private void listMatchingElements(Element element, String regex, boolean recurse) { // // First check attributes // List<Attribute> namedNodeMap = element.attributes(); if (null != namedNodeMap) { for (Attribute attribute : namedNodeMap) { String value = attribute.getValue(); if (Utils.containsRegex(value, regex)) { if (false == elementsMap.containsKey(element)) { elementsMap.put(element, null); elementsOrder.addFirst(element); } } } } // // Then check text // if (Utils.containsRegex(element.getText(), regex)) { if (false == elementsMap.containsKey(element)) { elementsMap.put(element, null); elementsOrder.addFirst(element); } } // // Finally elements // if (recurse) { List<Element> childrens = element.elements(); for (Element child : childrens) { listMatchingElements(child, regex, recurse); } } }
Example 9
Source File: XMLElementDefaultParser.java From mts with GNU General Public License v3.0 | 5 votes |
public List<Element> replace(Element element, ParameterPool parameterPool) throws Exception { List<Element> list = new LinkedList<Element>(); Element newElement = element.createCopy(); list.add(newElement); List<Attribute> attributes = newElement.attributes(); for (Attribute attribute : attributes) { String value = attribute.getValue(); LinkedList<String> parsedValue = parameterPool.parse(value); if (parsedValue.size() > 1) { throw new ExecutionException("Invalid size of variables in attribute " + value); } if (parsedValue.size() == 1) { attribute.setValue(parsedValue.getFirst()); } else { attribute.setValue(null); } } return list; }
Example 10
Source File: XmlToJson.java From Tpay with GNU General Public License v3.0 | 5 votes |
/** * org.dom4j.Element 转 com.alibaba.fastjson.JSONObject * * @param node * @return */ public static JSONObject elementToJSONObject(Element node) { JSONObject result = new JSONObject(); // 当前节点的名称、文本内容和属性 List<Attribute> listAttr = node.attributes();// 当前节点的所有属性的list for (Attribute attr : listAttr) {// 遍历当前节点的所有属性 result.put(attr.getName(), attr.getValue()); } // 递归遍历当前节点所有的子节点 List<Element> listElement = node.elements();// 所有一级子节点的list if (!listElement.isEmpty()) { for (Element e : listElement) {// 遍历所有一级子节点 if (e.attributes().isEmpty() && e.elements().isEmpty()) // 判断一级节点是否有属性和子节点 result.put(e.getName(), e.getTextTrim());// 沒有则将当前节点作为上级节点的属性对待 else { if (!result.containsKey(e.getName())) { // 判断父节点是否存在该一级节点名称的属性 if (getKeyCount(e.getName(), listElement) > 1) { result.put(e.getName(), new JSONArray());// 没有则创建 } else { result.put(e.getName(), elementToJSONObject(e));// 没有则创建 continue; } } ((JSONArray) result.get(e.getName())).add(elementToJSONObject(e));// 将该一级节点放入该节点名称的属性对应的值中 } } } return result; }
Example 11
Source File: XmlToJson.java From renrenpay-android with Apache License 2.0 | 5 votes |
/** * org.dom4j.Element 转 com.alibaba.fastjson.JSONObject * * @param node * @return */ public static JSONObject elementToJSONObject(Element node) { JSONObject result = new JSONObject(); // 当前节点的名称、文本内容和属性 List<Attribute> listAttr = node.attributes();// 当前节点的所有属性的list for (Attribute attr : listAttr) {// 遍历当前节点的所有属性 result.put(attr.getName(), attr.getValue()); } // 递归遍历当前节点所有的子节点 List<Element> listElement = node.elements();// 所有一级子节点的list if (!listElement.isEmpty()) { for (Element e : listElement) {// 遍历所有一级子节点 if (e.attributes().isEmpty() && e.elements().isEmpty()) // 判断一级节点是否有属性和子节点 result.put(e.getName(), e.getTextTrim());// 沒有则将当前节点作为上级节点的属性对待 else { if (!result.containsKey(e.getName())) { // 判断父节点是否存在该一级节点名称的属性 if (getKeyCount(e.getName(), listElement) > 1) { result.put(e.getName(), new JSONArray());// 没有则创建 } else { result.put(e.getName(), elementToJSONObject(e));// 没有则创建 continue; } } ((JSONArray) result.get(e.getName())).add(elementToJSONObject(e));// 将该一级节点放入该节点名称的属性对应的值中 } } } return result; }
Example 12
Source File: XmlUtil.java From Leo with Apache License 2.0 | 5 votes |
/** * 标签属性解析 * * @param e */ @SuppressWarnings("unchecked") private void AttriToMap(Element e) { List<Attribute> tempList = e.attributes(); for (int i = 0; i < tempList.size(); i++) { // 属性的取得 Attribute item = tempList.get(i); putMap(resultMap, item.getName(), item.getValue()); // resultMap.put(item.getName(), item.getValue()); } }
Example 13
Source File: AddSpringConfigurationPropertyMigrationTask.java From tesb-studio-se with Apache License 2.0 | 5 votes |
private void addIgnoreExchangeEventProperty(CamelProcessItem item) throws PersistenceException, DocumentException { String springContent = item.getSpringContent(); if (null != springContent && !springContent.isEmpty()) { Document document = DocumentHelper.parseText(springContent); QName qname = QName.get("bean", SPRING_BEANS_NAMESPACE); List<Element> beans = document.getRootElement().elements(qname); for (Element bean : beans) { if ("jmxEventNotifier".equals(bean.attributeValue("id")) && "org.apache.camel.management.JmxNotificationEventNotifier".equals(bean.attributeValue("class"))) { List<Element> properties = bean.elements(QName.get("property", SPRING_BEANS_NAMESPACE)); boolean hasIgnore = false; for (Element property : properties) { List<Attribute> propertyAttributes = property.attributes(); for (Attribute propertyAttribute : propertyAttributes) { if (propertyAttribute.getValue().equals(IGNORE_EXCHANGE_EVENTS)) { hasIgnore = true; break; } } } if (!hasIgnore) { DefaultElement ignoreExchangeElement = new DefaultElement("property", bean.getNamespace()); ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "name", IGNORE_EXCHANGE_EVENTS)); ignoreExchangeElement.add(DocumentHelper.createAttribute(ignoreExchangeElement, "value", "true")); bean.add(ignoreExchangeElement); item.setSpringContent(document.asXML()); saveItem(item); } break; } } } }
Example 14
Source File: Dom4j.java From cuba with Apache License 2.0 | 4 votes |
/** * @deprecated Use Dom4j API. */ @Deprecated public static List<Attribute> attributes(Element element) { return element.attributes(); }
Example 15
Source File: Dom4j.java From cuba with Apache License 2.0 | 4 votes |
public static void walkAttributes(Element element, ElementAttributeVisitor visitor) { for (Attribute attribute : element.attributes()) { visitor.onVisit(element, attribute); } }
Example 16
Source File: XMLInputFieldsImportProgressDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unchecked" ) private void setNodeField( Node node, IProgressMonitor monitor ) { Element e = (Element) node; // get all attributes List<Attribute> lista = e.attributes(); for ( int i = 0; i < lista.size(); i++ ) { setAttributeField( lista.get( i ), monitor ); } // Get Node Name String nodename = node.getName(); String nodenametxt = cleanString( node.getPath() ); if ( !Utils.isEmpty( nodenametxt ) && !list.contains( nodenametxt ) ) { nr++; monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields", String.valueOf( nr ) ) ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField", nodename ) ); RowMetaAndData row = new RowMetaAndData(); row.addValue( VALUE_NAME, Value.VALUE_TYPE_STRING, nodename ); row.addValue( VALUE_PATH, Value.VALUE_TYPE_STRING, nodenametxt ); row.addValue( VALUE_ELEMENT, Value.VALUE_TYPE_STRING, GetXMLDataField.ElementTypeDesc[0] ); row.addValue( VALUE_RESULT, Value.VALUE_TYPE_STRING, GetXMLDataField.ResultTypeDesc[0] ); // Get Node value String valueNode = node.getText(); // Try to get the Type if ( IsDate( valueNode ) ) { row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Date" ); row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, "yyyy/MM/dd" ); } else if ( IsInteger( valueNode ) ) { row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Integer" ); row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null ); } else if ( IsNumber( valueNode ) ) { row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "Number" ); row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null ); } else { row.addValue( VALUE_TYPE, Value.VALUE_TYPE_STRING, "String" ); row.addValue( VALUE_FORMAT, Value.VALUE_TYPE_STRING, null ); } fieldsList.add( row ); list.add( nodenametxt ); } // end if }
Example 17
Source File: XmlInputFieldsImportProgressDialog.java From hop with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unchecked" ) private void setNodeField( Node node, IProgressMonitor monitor ) { Element e = (Element) node; // get all attributes List<Attribute> lista = e.attributes(); for ( int i = 0; i < lista.size(); i++ ) { setAttributeField( lista.get( i ), monitor ); } // Get Node Name String nodename = node.getName(); String nodenametxt = cleanString( node.getPath() ); if ( !Utils.isEmpty( nodenametxt ) && !list.contains( nodenametxt ) ) { nr++; monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields", String.valueOf( nr ) ) ); monitor.subTask( BaseMessages.getString( PKG, "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField", nodename ) ); RowMetaAndData row = new RowMetaAndData(); row.addValue( VALUE_NAME, IValueMeta.TYPE_STRING, nodename ); row.addValue( VALUE_PATH, IValueMeta.TYPE_STRING, nodenametxt ); row.addValue( VALUE_ELEMENT, IValueMeta.TYPE_STRING, GetXmlDataField.ElementTypeDesc[0] ); row.addValue( VALUE_RESULT, IValueMeta.TYPE_STRING, GetXmlDataField.ResultTypeDesc[0] ); // Get Node value String valueNode = node.getText(); // Try to get the Type if ( IsDate( valueNode ) ) { row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Date" ); row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, "yyyy/MM/dd" ); } else if ( IsInteger( valueNode ) ) { row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Integer" ); row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null ); } else if ( IsNumber( valueNode ) ) { row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "Number" ); row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null ); } else { row.addValue( VALUE_TYPE, IValueMeta.TYPE_STRING, "String" ); row.addValue( VALUE_FORMAT, IValueMeta.TYPE_STRING, null ); } fieldsList.add( row ); list.add( nodenametxt ); } // end if }
Example 18
Source File: Host.java From big-c with Apache License 2.0 | 3 votes |
public synchronized void Parse(Element node){ if(node.getName() != "CLUSTER"){ } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="IP"){ this.setIp(attribute.getValue()); } } //then parse the child nodes for (Iterator iterator = node.elementIterator( "METRIC" ); iterator.hasNext(); ) { Element element = (Element) iterator.next(); String name = element.attribute("NAME").getValue(); Metric metric= new Metric(); metric.Parse(element); this.nameToMetrics.put(name, metric); } }
Example 19
Source File: Grid.java From big-c with Apache License 2.0 | 2 votes |
void Parse(Element node){ if(node.getName() != "GRID"){ } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="AUTHORITY"){ this.setAutority(attribute.getValue()); } if(attribute.getName()=="LOCALTIME"){ this.setLocalTime(attribute.getValue()); } } //then parse the child nodes for (Iterator iterator = node.elementIterator( "CLUSTER" ); iterator.hasNext(); ) { Element element = (Element) iterator.next(); String name = element.attribute("NAME").getValue(); System.out.println("cluster name"+name); Cluster cluster= new Cluster(); cluster.Parse(element); this.nameToClusters.put(name, cluster); } }
Example 20
Source File: Cluster.java From big-c with Apache License 2.0 | 2 votes |
public synchronized void Parse(Element node){ if(node.getName() != "CLUSTER"){ } List<Attribute> arrtibuteList = node.attributes(); //first initialize or update attributes for(Attribute attribute : arrtibuteList){ if(attribute.getName() == "NAME"){ this.setName(attribute.getValue()); } if(attribute.getName()=="OWNER"){ this.setOwner(attribute.getValue()); } if(attribute.getName()=="LOCALTIME"){ this.setLocalTime(attribute.getValue()); } if(attribute.getName() == "LATLONG"){ this.setLatLong(attribute.getValue()); } if(attribute.getName()=="URL"){ this.setUrl(attribute.getValue()); } } //then parse the child nodes for (Iterator iterator = node.elementIterator( "HOST" ); iterator.hasNext(); ) { Element element = (Element) iterator.next(); String name = element.attribute("NAME").getValue(); Host host= new Host(); host.Parse(element); this.nameToHost.put(name, host); } }