List of usage examples for org.jdom2 Element removeAttribute
public boolean removeAttribute(final Attribute attribute)
This removes the supplied Attribute should it exist.
From source file:org.workflow.WorkflowParser.java
License:Apache License
private void modifyXmlFile(String path) { try {// w w w.jav a 2 s . c o m SAXBuilder builder = new SAXBuilder(); //parse using builder to get DOM representation of the XML file Document dom = builder.build(new File(path)); Element root = dom.getRootElement(); List<Element> list = root.getChildren(); for (Element node : list) { switch (node.getName().toLowerCase()) { case "job": double runtime; if (node.getAttributeValue("runtime") != null) { Attribute att = node.getAttribute("runtime"); att.setValue("20"); node.removeAttribute("runtime"); node.setAttribute(att); } break; default: break; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.xflatdb.xflat.query.XPathUpdate.java
License:Apache License
/** * Applies the update operations to the given DOM Element representing * the data in a selected row.//w w w.j ava 2s. co m * @param rowData The DOM Element representing the data in a selected row. * @return true if any updates were applied. */ public int apply(Element rowData) { int updateCount = 0; for (Update update : this.updates) { //the update's value will be one or the other, don't know which Content asContent = null; String asString = null; if (update.value instanceof String) { asString = (String) update.value; } if (update.value instanceof Content) { asContent = (Content) update.value; } for (Object node : update.path.evaluate(rowData)) { if (node == null) continue; Parent parent; Element parentElement; if (update.getUpdateType() == UpdateType.UNSET) { if (node instanceof Attribute) { parentElement = ((Attribute) node).getParent(); if (parentElement != null) { parentElement.removeAttribute((Attribute) node); updateCount++; } } else if (node instanceof Content) { parent = ((Content) node).getParent(); //remove this node from its parent element if (parent != null) { parent.removeContent((Content) node); updateCount++; } } continue; } //it's a set if (node instanceof Attribute) { //for attributes we set the value to empty string //this way it can still be selected by xpath for future updates if (update.value == null) { ((Attribute) node).setValue(""); updateCount++; } else { if (asString == null) { asString = getStringValue(update.value); } //if we fail conversion then do nothing. if (asString != null) { ((Attribute) node).setValue(asString); updateCount++; } } continue; } else if (!(node instanceof Content)) { //can't do anything continue; } Content contentNode = (Content) node; //need to convert if (update.value != null && asContent == null) { asContent = getContentValue(update.value); if (asContent == null) { //failed conversion, try text asString = getStringValue(update.value); if (asString != null) { //success! asContent = new Text(asString); } } } if (node instanceof Element) { //for elements we also set the value, but the value could be Content if (update.value == null) { ((Element) node).removeContent(); updateCount++; } else if (asContent != null) { if (asContent.getParent() != null) { //we used the content before, need to clone it asContent = asContent.clone(); } ((Element) node).setContent(asContent); updateCount++; } continue; } //at this point the node is Text, CDATA or something else. //The strategy now is to replace the value in its parent. parentElement = contentNode.getParentElement(); if (parentElement == null) { //can't do anything continue; } if (update.value == null || asContent != null) { //replace this content in the parent element int index = parentElement.indexOf(contentNode); parentElement.removeContent(index); if (update.value != null) { //if it was null then act like an unset, otherwise //its a replace if (asContent.getParent() != null) { //we used the content before, need to clone it asContent = asContent.clone(); } parentElement.addContent(index, asContent); } updateCount++; } } } return updateCount; }
From source file:org.yawlfoundation.yawl.scheduling.util.XMLUtils.java
License:Open Source License
public static void removeAttribute(Element e, String attr) { try {//from www . ja v a 2 s . co m e.removeAttribute(attr); } catch (Exception e1) { logger.error("cannot remove Attribute", e1); } }
From source file:password.pwm.config.stored.StoredConfigurationImpl.java
License:Open Source License
private static void updateMetaData(final Element settingElement, final UserIdentity userIdentity) { final Element settingsElement = settingElement.getDocument().getRootElement() .getChild(XML_ELEMENT_SETTINGS); settingElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now())); settingsElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now())); settingElement.removeAttribute(XML_ATTRIBUTE_MODIFY_USER); settingsElement.removeAttribute(XML_ATTRIBUTE_MODIFY_USER); if (userIdentity != null) { settingElement.setAttribute(XML_ATTRIBUTE_MODIFY_USER, userIdentity.toDelimitedKey()); settingsElement.setAttribute(XML_ATTRIBUTE_MODIFY_USER, userIdentity.toDelimitedKey()); }/*from w w w . ja v a 2 s . c o m*/ }
From source file:password.pwm.config.StoredConfiguration.java
License:Open Source License
private static void updateMetaData(final Element settingElement, final UserIdentity userIdentity) { final Element settingsElement = settingElement.getDocument().getRootElement() .getChild(XML_ELEMENT_SETTINGS); settingElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, PwmConstants.DEFAULT_DATETIME_FORMAT.format(new Date())); settingsElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, PwmConstants.DEFAULT_DATETIME_FORMAT.format(new Date())); settingElement.removeAttribute(XML_ATTRIBUTE_MODIFY_USER); settingsElement.removeAttribute(XML_ATTRIBUTE_MODIFY_USER); if (userIdentity != null) { settingElement.setAttribute(XML_ATTRIBUTE_MODIFY_USER, userIdentity.toDelimitedKey()); settingsElement.setAttribute(XML_ATTRIBUTE_MODIFY_USER, userIdentity.toDelimitedKey()); }/*from w w w . ja v a 2 s . c o m*/ }