Refine search
/** * Common routine to remove all children nodes from the passed element container * @param parentElement * @param nodeName * @throws XPathExpressionException */ protected void clearNode(Element parentElement, String nodeName) throws XPathExpressionException { if (parentElement.hasChildNodes()) { NodeList children = (NodeList) xPath.evaluate(nodeName, parentElement, XPathConstants.NODESET); for (int j = 0; j < children.getLength(); j++) { parentElement.removeChild(children.item(j)); } children = parentElement.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { if (children.item(j).getNodeName().equalsIgnoreCase("#text")) { parentElement.removeChild(children.item(j)); } } } }
element.removeChild(txtNode); if (element.getFirstChild() != null) element.insertBefore(txtNode, element.getFirstChild());
/** * Removes the mime mapping at the specified index. * * @param index int */ public void removeMimeMapping(int index) { Element element = webAppDocument.getDocumentElement(); NodeList list = element.getElementsByTagName("mime-mapping"); Node node = list.item(index); element.removeChild(node); isWebAppDirty = true; }
private static void swallowStartElement(Element root) { NamedNodeMap attrMap = root.getAttributes(); NodeList childNodes = root.getChildNodes(); if(attrMap.getLength() == 0 && childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.ELEMENT_NODE) { Element child = (Element)childNodes.item(0); if(child.getNodeName().equals(root.getNodeName())) { NamedNodeMap attrs = child.getAttributes(); for(int i=0; i<attrs.getLength(); i++) { Attr attrNode = (Attr)attrs.item(i); root.setAttributeNode(((Attr)attrNode.cloneNode(true))); } while(child.hasChildNodes()) { root.appendChild(child.removeChild(child.getFirstChild())); } root.removeChild(child); } } }
/** * Moves all child elements of the parent into destination element. * * @param parent the parent {@link Element}. * @param destination the destination {@link Element}. */ protected void moveChildren(Element parent, Element destination) { NodeList children = parent.getChildNodes(); while (children.getLength() > 0) { destination.appendChild(parent.removeChild(parent.getFirstChild())); } } }
for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { trimEmptyTextNodes(child); element.removeChild(n);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = factory.newDocumentBuilder().parse("booking-request.xml"); Element bookingRequest = doc.getDocumentElement(); Element contract = (Element)bookingRequest.getElementsByTagName("Contract").item(0); Element trades = (Element)contract.getElementsByTagName("Trades").item(0); List<Element> tradeList = new ArrayList<Element>(); NodeList nodeList = trades.getElementsByTagName("Trade"); for(int i=0; i<nodeList.getLength(); i++) tradeList.add((Element)nodeList.item(i)); Transformer transformer = TransformerFactory.newInstance().newTransformer(); int i = 0; for(Element trade: tradeList){ // remove all children of <Trades> while(trades.getFirstChild()!=null) trades.removeChild(trades.getFirstChild()); trades.appendChild(doc.createTextNode("\n ")); trades.appendChild(trade); trades.appendChild(doc.createTextNode("\n ")); ++i; transformer.transform(new DOMSource(doc), new StreamResult(new File("trade"+i+".xml"))); }
private static void removeEventTimeNode(Document document) { final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS( XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0); document.getDocumentElement().removeChild(eventTimeNode); }
/** * Moves all child elements of the parent into destination element. * * @param parent the parent {@link Element}. * @param destination the destination {@link Element}. */ protected void moveChildren(Element parent, Element destination) { NodeList children = parent.getChildNodes(); while (children.getLength() > 0) { destination.appendChild(parent.removeChild(parent.getFirstChild())); } } }
public static void clear(Element root) { Node child; while (true) { child = root.getFirstChild(); if (child == null) { break; } root.removeChild(child); } }
for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { trimEmptyTextNodes(child); element.removeChild(n);
private Map<File, Map<String, Element>> getMapping(Document doc) { final Map<File, Map<String, Element>> map = new HashMap<>(); final NodeList maplinks = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < maplinks.getLength(); i++) { final Node n = maplinks.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { final Element maplink = (Element) n; final URI href = toURI(maplink.getAttribute(ATTRIBUTE_NAME_HREF)); final File path = toFile(stripFragment(href)); String fragment = href.getFragment(); if (fragment == null) { fragment = SHARP; } Map<String, Element> m = map.computeIfAbsent(path, k -> new HashMap<>()); Element stub = m.computeIfAbsent(fragment, k -> doc.createElement("stub")); Node c = maplink.getFirstChild(); while (c != null) { final Node nextSibling = c.getNextSibling(); stub.appendChild(maplink.removeChild(c)); c = nextSibling; } } } return map; }
public void applyXSW6(Document document){ Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0); Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0); Element assertion = (Element) evilAssertion.cloneNode(true); Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0); assertion.removeChild(copiedSignature); originalSignature.appendChild(assertion); evilAssertion.setAttribute("ID", "_evil_assertion_ID"); }
void convert(Element latexElement) throws IOException { String rawInputLaTeX = latexElement.getTextContent(); String inputLaTeX = rawInputLaTeX.replaceAll("(\r\n|\r|\n)", "\n"); SnuggleEngine engine = createSnuggleEngine(); SnuggleSession session = engine.createSession(); SnuggleInput input = new SnuggleInput(inputLaTeX, "LaTeX Element"); try { session.parseInput(input); } catch (Exception e) { throw new IOException("Error while parsing: " + rawInputLaTeX + ": " + e.getMessage(), e); } while (latexElement.getChildNodes().getLength() != 0) latexElement.removeChild(latexElement.getFirstChild()); DOMOutputOptions options = new DOMOutputOptions(); options.setErrorOutputOptions(DOMOutputOptions.ErrorOutputOptions.XHTML); try { session.buildDOMSubtree(latexElement, options); } catch (Exception e) { throw new IOException("Error while building DOM for: " + rawInputLaTeX + ": " + e.getMessage(), e); } }
private static void clearChildren(Element elem) { // TODO(rjrjr) I'm nearly positive that anywhere this is called // we should instead be calling assertNoBody Node child; while ((child = elem.getFirstChild()) != null) { elem.removeChild(child); } }
for (int i = 0; i < oldComments.getLength(); i++) { Node node = oldComments.item(i); if (node.getNodeType() == Node.COMMENT_NODE && node.getNodeValue().equals(name)) { addComment = false; org.w3c.dom.Element former = find(file, entry.getKey(), "attr"); if (former != null) { file.removeChild(former); } else if (contents != null) { NodeList oldContents = file.getChildNodes(); for (int i = 0; i < oldContents.getLength();) { Node node = oldContents.item(i); if (node.getNodeType() == Node.CDATA_SECTION_NODE) { file.removeChild(node); } else { i++;
public void applyXSW3(Document document){ Element assertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0); Element evilAssertion = (Element) assertion.cloneNode(true); Element copiedSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0); evilAssertion.setAttribute("ID", "_evil_assertion_ID"); evilAssertion.removeChild(copiedSignature); document.getDocumentElement().insertBefore(evilAssertion, assertion); }
private final void empty(Element element) { Node child; while ((child = element.getFirstChild()) != null) element.removeChild(child); }
for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof DocumentType) { doctype = (DocumentType) nl.item(i); doc = builder.newDocument(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (!(node instanceof DocumentType)) { try { for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); removeXmlBase(e); Node n = nl2.item(j); if (n instanceof Text && ((Text) n).getNodeValue().trim().length() == 0) { e.removeChild(n);
public void applyXSW8(Document document){ Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0); Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0); Element assertion = (Element) evilAssertion.cloneNode(true); Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0); assertion.removeChild(copiedSignature); Element object = document.createElement("Object"); originalSignature.appendChild(object); object.appendChild(assertion); }