List of usage examples for org.jdom2 Element setContent
public Parent setContent(final int index, final Collection<? extends Content> newContent)
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.UnaryOperatorRemover.java
License:Apache License
private void removeUnaryOperator(final Element rootElem) { assert rootElem != null; /* Presentation MathML */ final Set<String> pmCharsToRemove = getPropertySet(PM_UNARY_OPERATORS_TO_REMOVE); if (!pmCharsToRemove.isEmpty()) { // Unary operators List<Element> pmElemsToRemove = xpPMUnaryOperators.evaluate(rootElem); for (Element toRemove : pmElemsToRemove) { if (pmCharsToRemove.contains(toRemove.getValue())) { LOGGER.finest("Removing element '" + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'."); toRemove.detach();/*from w w w. j a v a2s.co m*/ } else { LOGGER.finest("Skipping element '" + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'."); } } // Second of the double operators pmElemsToRemove = xpPMSecondOperatorInDoubleOperators.evaluate(rootElem); for (Element toRemove : pmElemsToRemove) { if (pmCharsToRemove.contains(toRemove.getValue())) { LOGGER.finest("Removing the second element out of double elements '" + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'."); toRemove.detach(); } else { LOGGER.finest("Skipping the second element out of double elements '" + toRemove.getQualifiedName() + "' with value '" + toRemove.getValue() + "'."); } } } LOGGER.finer("RemoveUnaryOperator Presentation MathML finished"); /* Content MathML */ List<Element> applyWithTwoChildrens = xpCMApplyWithTwoChildrens.evaluate(rootElem); final Set<String> cmOperatorsToRemove = getPropertySet(CM_UNARY_OPERATORS_TO_REMOVE); for (Element applyElem : applyWithTwoChildrens) { Element operator = applyElem.getChildren().get(0); if (cmOperatorsToRemove.contains(operator.getName())) { Element operand = applyElem.getChildren().get(1); LOGGER.finest("Removing operator '" + operator.getQualifiedName() + "' for operand '" + operand.getQualifiedName() + "'."); operand.detach(); Element parent = applyElem.getParentElement(); int applyElemIndex = parent.indexOf(applyElem); parent.setContent(applyElemIndex, operand); applyElem.detach(); } } LOGGER.finer("RemoveUnaryOperator Content MathML finished"); }
From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java
License:Creative Commons License
/** * Update member contents with resolved data * //w w w . j a v a 2s .c o m * @param node * @param memberReference * @param memberDocument * @return * @throws Exception */ private static Element updateMember(Element node, EReference memberReference, int id, EObject memberObject, Document memberDocument) throws Exception { Namespace namespace = node.getNamespace(modelMetaData.getNamespace(memberReference)); List<Element> children = null; if (namespace == null) { children = node.getChildren(modelMetaData.getName(memberReference)); } else throw new IllegalArgumentException(); if (id < children.size()) { // Inserting resolved contents to the member Element element = children.get(id); Element clone = memberDocument.getRootElement().clone(); clone.setName(memberReference.getName()); node.setContent(node.indexOf(element), clone); // Setting xsi:type clone.setAttribute("type", memberObject.eClass().getEPackage().getName() + ":" + memberObject.eClass().getName(), node.getNamespace("xsi")); } return node; }
From source file:XMLWriter.WriteUsersXML.java
License:Open Source License
public static boolean addCourse(String idUser, String idCourse, String xmlSource) { try {//w ww . j a va 2 s .c om Document doc = builder.build(xmlSource); Element rootNode = doc.getRootElement(); boolean find = false; for (Element e : rootNode.getChildren("user", ns)) if (e.getAttributeValue("id").equals(idUser)) { find = true; Element idCu = new Element("idCurso", ns); idCu.setText(idCourse); e.setContent(e.indexOf(e.getChild("idCurso", ns)), idCu); break; } if (!find) return false; Format form = Format.getPrettyFormat().clone(); form.setTextMode(Format.TextMode.TRIM_FULL_WHITE); XMLOutputter xmlOut = new XMLOutputter(form); FileOutputStream file = new FileOutputStream(xmlSource); xmlOut.output(doc, file); file.close(); } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } return true; }