org.w3c.dom.Element.removeChild()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(349)

本文整理了Java中org.w3c.dom.Element.removeChild()方法的一些代码示例,展示了Element.removeChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.removeChild()方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:removeChild

Element.removeChild介绍

暂无

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

  1. /**
  2. * Common routine to remove all children nodes from the passed element container
  3. * @param parentElement
  4. * @param nodeName
  5. * @throws XPathExpressionException
  6. */
  7. protected void clearNode(Element parentElement, String nodeName) throws XPathExpressionException {
  8. if (parentElement.hasChildNodes()) {
  9. NodeList children = (NodeList) xPath.evaluate(nodeName, parentElement, XPathConstants.NODESET);
  10. for (int j = 0; j < children.getLength(); j++) {
  11. parentElement.removeChild(children.item(j));
  12. }
  13. children = parentElement.getChildNodes();
  14. for (int j = 0; j < children.getLength(); j++) {
  15. if (children.item(j).getNodeName().equalsIgnoreCase("#text")) {
  16. parentElement.removeChild(children.item(j));
  17. }
  18. }
  19. }
  20. }

代码示例来源:origin: org.apache.commons/commons-configuration2

  1. element.removeChild(txtNode);
  2. if (element.getFirstChild() != null)
  3. element.insertBefore(txtNode, element.getFirstChild());

代码示例来源:origin: org.eclipse/org.eclipse.jst.server.tomcat.core

  1. /**
  2. * Removes the mime mapping at the specified index.
  3. *
  4. * @param index int
  5. */
  6. public void removeMimeMapping(int index) {
  7. Element element = webAppDocument.getDocumentElement();
  8. NodeList list = element.getElementsByTagName("mime-mapping");
  9. Node node = list.item(index);
  10. element.removeChild(node);
  11. isWebAppDirty = true;
  12. }

代码示例来源:origin: org.pustefixframework/pustefix-core

  1. private static void swallowStartElement(Element root) {
  2. NamedNodeMap attrMap = root.getAttributes();
  3. NodeList childNodes = root.getChildNodes();
  4. if(attrMap.getLength() == 0 && childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
  5. Element child = (Element)childNodes.item(0);
  6. if(child.getNodeName().equals(root.getNodeName())) {
  7. NamedNodeMap attrs = child.getAttributes();
  8. for(int i=0; i<attrs.getLength(); i++) {
  9. Attr attrNode = (Attr)attrs.item(i);
  10. root.setAttributeNode(((Attr)attrNode.cloneNode(true)));
  11. }
  12. while(child.hasChildNodes()) {
  13. root.appendChild(child.removeChild(child.getFirstChild()));
  14. }
  15. root.removeChild(child);
  16. }
  17. }
  18. }

代码示例来源:origin: org.xwiki.platform/xwiki-core-xml

  1. /**
  2. * Moves all child elements of the parent into destination element.
  3. *
  4. * @param parent the parent {@link Element}.
  5. * @param destination the destination {@link Element}.
  6. */
  7. protected void moveChildren(Element parent, Element destination)
  8. {
  9. NodeList children = parent.getChildNodes();
  10. while (children.getLength() > 0) {
  11. destination.appendChild(parent.removeChild(parent.getFirstChild()));
  12. }
  13. }
  14. }

代码示例来源:origin: marytts/marytts

  1. for (int i = 0; i < children.getLength(); i++) {
  2. Node child = children.item(i);
  3. if (child instanceof Element) {
  4. trimEmptyTextNodes(child);
  5. element.removeChild(n);

代码示例来源:origin: stackoverflow.com

  1. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  2. Document doc = factory.newDocumentBuilder().parse("booking-request.xml");
  3. Element bookingRequest = doc.getDocumentElement();
  4. Element contract = (Element)bookingRequest.getElementsByTagName("Contract").item(0);
  5. Element trades = (Element)contract.getElementsByTagName("Trades").item(0);
  6. List<Element> tradeList = new ArrayList<Element>();
  7. NodeList nodeList = trades.getElementsByTagName("Trade");
  8. for(int i=0; i<nodeList.getLength(); i++)
  9. tradeList.add((Element)nodeList.item(i));
  10. Transformer transformer = TransformerFactory.newInstance().newTransformer();
  11. int i = 0;
  12. for(Element trade: tradeList){
  13. // remove all children of <Trades>
  14. while(trades.getFirstChild()!=null)
  15. trades.removeChild(trades.getFirstChild());
  16. trades.appendChild(doc.createTextNode("\n "));
  17. trades.appendChild(trade);
  18. trades.appendChild(doc.createTextNode("\n "));
  19. ++i;
  20. transformer.transform(new DOMSource(doc), new StreamResult(new File("trade"+i+".xml")));
  21. }

代码示例来源:origin: org.opendaylight.netconf/netconf-util

  1. private static void removeEventTimeNode(Document document) {
  2. final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS(
  3. XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0);
  4. document.getDocumentElement().removeChild(eventTimeNode);
  5. }

代码示例来源:origin: org.xwiki.commons/xwiki-commons-xml

  1. /**
  2. * Moves all child elements of the parent into destination element.
  3. *
  4. * @param parent the parent {@link Element}.
  5. * @param destination the destination {@link Element}.
  6. */
  7. protected void moveChildren(Element parent, Element destination)
  8. {
  9. NodeList children = parent.getChildNodes();
  10. while (children.getLength() > 0) {
  11. destination.appendChild(parent.removeChild(parent.getFirstChild()));
  12. }
  13. }
  14. }

代码示例来源:origin: net.oneandone/sushi

  1. public static void clear(Element root) {
  2. Node child;
  3. while (true) {
  4. child = root.getFirstChild();
  5. if (child == null) {
  6. break;
  7. }
  8. root.removeChild(child);
  9. }
  10. }

代码示例来源:origin: marytts/marytts

  1. for (int i = 0; i < children.getLength(); i++) {
  2. Node child = children.item(i);
  3. if (child instanceof Element) {
  4. trimEmptyTextNodes(child);
  5. element.removeChild(n);

代码示例来源:origin: dita-ot/dita-ot

  1. private Map<File, Map<String, Element>> getMapping(Document doc) {
  2. final Map<File, Map<String, Element>> map = new HashMap<>();
  3. final NodeList maplinks = doc.getDocumentElement().getChildNodes();
  4. for (int i = 0; i < maplinks.getLength(); i++) {
  5. final Node n = maplinks.item(i);
  6. if (n.getNodeType() == Node.ELEMENT_NODE) {
  7. final Element maplink = (Element) n;
  8. final URI href = toURI(maplink.getAttribute(ATTRIBUTE_NAME_HREF));
  9. final File path = toFile(stripFragment(href));
  10. String fragment = href.getFragment();
  11. if (fragment == null) {
  12. fragment = SHARP;
  13. }
  14. Map<String, Element> m = map.computeIfAbsent(path, k -> new HashMap<>());
  15. Element stub = m.computeIfAbsent(fragment, k -> doc.createElement("stub"));
  16. Node c = maplink.getFirstChild();
  17. while (c != null) {
  18. final Node nextSibling = c.getNextSibling();
  19. stub.appendChild(maplink.removeChild(c));
  20. c = nextSibling;
  21. }
  22. }
  23. }
  24. return map;
  25. }

代码示例来源:origin: SAMLRaider/SAMLRaider

  1. public void applyXSW6(Document document){
  2. Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
  3. Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
  4. Element assertion = (Element) evilAssertion.cloneNode(true);
  5. Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0);
  6. assertion.removeChild(copiedSignature);
  7. originalSignature.appendChild(assertion);
  8. evilAssertion.setAttribute("ID", "_evil_assertion_ID");
  9. }

代码示例来源:origin: danfickle/openhtmltopdf

  1. void convert(Element latexElement) throws IOException {
  2. String rawInputLaTeX = latexElement.getTextContent();
  3. String inputLaTeX = rawInputLaTeX.replaceAll("(\r\n|\r|\n)", "\n");
  4. SnuggleEngine engine = createSnuggleEngine();
  5. SnuggleSession session = engine.createSession();
  6. SnuggleInput input = new SnuggleInput(inputLaTeX, "LaTeX Element");
  7. try {
  8. session.parseInput(input);
  9. } catch (Exception e) {
  10. throw new IOException("Error while parsing: " + rawInputLaTeX + ": " + e.getMessage(), e);
  11. }
  12. while (latexElement.getChildNodes().getLength() != 0)
  13. latexElement.removeChild(latexElement.getFirstChild());
  14. DOMOutputOptions options = new DOMOutputOptions();
  15. options.setErrorOutputOptions(DOMOutputOptions.ErrorOutputOptions.XHTML);
  16. try {
  17. session.buildDOMSubtree(latexElement, options);
  18. } catch (Exception e) {
  19. throw new IOException("Error while building DOM for: " + rawInputLaTeX + ": " + e.getMessage(), e);
  20. }
  21. }

代码示例来源:origin: net.wetheinter/gwt-user

  1. private static void clearChildren(Element elem) {
  2. // TODO(rjrjr) I'm nearly positive that anywhere this is called
  3. // we should instead be calling assertNoBody
  4. Node child;
  5. while ((child = elem.getFirstChild()) != null) {
  6. elem.removeChild(child);
  7. }
  8. }

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

  1. for (int i = 0; i < oldComments.getLength(); i++) {
  2. Node node = oldComments.item(i);
  3. if (node.getNodeType() == Node.COMMENT_NODE && node.getNodeValue().equals(name)) {
  4. addComment = false;
  5. org.w3c.dom.Element former = find(file, entry.getKey(), "attr");
  6. if (former != null) {
  7. file.removeChild(former);
  8. } else if (contents != null) {
  9. NodeList oldContents = file.getChildNodes();
  10. for (int i = 0; i < oldContents.getLength();) {
  11. Node node = oldContents.item(i);
  12. if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
  13. file.removeChild(node);
  14. } else {
  15. i++;

代码示例来源:origin: SAMLRaider/SAMLRaider

  1. public void applyXSW3(Document document){
  2. Element assertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
  3. Element evilAssertion = (Element) assertion.cloneNode(true);
  4. Element copiedSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
  5. evilAssertion.setAttribute("ID", "_evil_assertion_ID");
  6. evilAssertion.removeChild(copiedSignature);
  7. document.getDocumentElement().insertBefore(evilAssertion, assertion);
  8. }

代码示例来源:origin: org.jooq/joox-java-6

  1. private final void empty(Element element) {
  2. Node child;
  3. while ((child = element.getFirstChild()) != null)
  4. element.removeChild(child);
  5. }

代码示例来源:origin: org.netbeans.api/org-openide-util

  1. for (int i = 0; i < nl.getLength(); i++) {
  2. if (nl.item(i) instanceof DocumentType) {
  3. doctype = (DocumentType) nl.item(i);
  4. doc = builder.newDocument();
  5. for (int i = 0; i < nl.getLength(); i++) {
  6. Node node = nl.item(i);
  7. if (!(node instanceof DocumentType)) {
  8. try {
  9. for (int i = 0; i < nl.getLength(); i++) {
  10. Element e = (Element) nl.item(i);
  11. removeXmlBase(e);
  12. Node n = nl2.item(j);
  13. if (n instanceof Text && ((Text) n).getNodeValue().trim().length() == 0) {
  14. e.removeChild(n);

代码示例来源:origin: SAMLRaider/SAMLRaider

  1. public void applyXSW8(Document document){
  2. Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
  3. Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
  4. Element assertion = (Element) evilAssertion.cloneNode(true);
  5. Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0);
  6. assertion.removeChild(copiedSignature);
  7. Element object = document.createElement("Object");
  8. originalSignature.appendChild(object);
  9. object.appendChild(assertion);
  10. }

相关文章