Example usage for org.w3c.dom Element removeChild

List of usage examples for org.w3c.dom Element removeChild

Introduction

In this page you can find the example usage for org.w3c.dom Element removeChild.

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

From source file:org.ojbc.bundles.adapters.staticmock.AbstractStaticMockTest.java

protected Document buildBasePersonSearchRequestMessagePersonNameOnly(String systemId) throws Exception {

    Document personSearchRequestMessage = buildBasePersonSearchRequestMessage(systemId);
    Element personElement = (Element) XmlUtils.xPathNodeSearch(personSearchRequestMessage,
            "psr-doc:PersonSearchRequest/psr:Person");
    NodeList children = personElement.getChildNodes();

    int childCount = children.getLength();

    for (int i = childCount - 1; i >= 0; i--) {

        Node child = children.item(i);
        if (!("PersonName".equals(child.getLocalName()))) {
            personElement.removeChild(child);
        }//from   w  w w  . j  av  a  2s.  co  m
    }
    // XmlUtils.printNode(personSearchRequestMessage);
    return personSearchRequestMessage;
}

From source file:org.ojbc.bundles.adapters.TestStaticMockAdapter.java

private Document buildCriminalHistoryPersonSearchMessage() throws Exception {
    Document personSearchRequestMessage = buildPersonSearchRequestMessagePersonNameOnly(
            StaticMockQuery.CRIMINAL_HISTORY_MOCK_ADAPTER_SEARCH_SYSTEM_ID);
    Element personElement = (Element) XmlUtils.xPathNodeSearch(personSearchRequestMessage,
            "psr-doc:PersonSearchRequest/psr:Person");
    Element personNameElement = (Element) XmlUtils.xPathNodeSearch(personElement, "nc:PersonName");
    Element lastNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonSurName");
    lastNameElement.setTextContent("Ivey");
    Element firstNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonGivenName");
    personNameElement.removeChild(firstNameElement);
    Element middleNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonMiddleName");
    personNameElement.removeChild(middleNameElement);
    return personSearchRequestMessage;
}

From source file:org.ojbc.bundles.adapters.TestStaticMockAdapter.java

private Document buildJuvenileHistoryPersonSearchMessage() throws Exception {
    Document personSearchRequestMessage = buildPersonSearchRequestMessagePersonNameOnly(
            StaticMockQuery.JUVENILE_HISTORY_MOCK_ADAPTER_SEARCH_SYSTEM_ID);
    Element personElement = (Element) XmlUtils.xPathNodeSearch(personSearchRequestMessage,
            "psr-doc:PersonSearchRequest/psr:Person");
    Element personNameElement = (Element) XmlUtils.xPathNodeSearch(personElement, "nc:PersonName");
    Element lastNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonSurName");
    lastNameElement.setTextContent("Mosley");
    Element firstNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonGivenName");
    personNameElement.removeChild(firstNameElement);
    Element middleNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonMiddleName");
    personNameElement.removeChild(middleNameElement);
    return personSearchRequestMessage;
}

From source file:org.ojbc.bundles.adapters.TestStaticMockAdapter.java

private Document buildFirearmsPersonSearchMessage() throws Exception {
    Document personSearchRequestMessage = buildPersonSearchRequestMessagePersonNameOnly(
            StaticMockQuery.FIREARM_MOCK_ADAPTER_SEARCH_SYSTEM_ID);
    Element personElement = (Element) XmlUtils.xPathNodeSearch(personSearchRequestMessage,
            "psr-doc:PersonSearchRequest/psr:Person");
    Element personNameElement = (Element) XmlUtils.xPathNodeSearch(personElement, "nc:PersonName");
    Element lastNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonSurName");
    lastNameElement.setTextContent("McElroy");
    Element firstNameElement = (Element) XmlUtils.xPathNodeSearch(personNameElement, "nc:PersonGivenName");
    personNameElement.removeChild(firstNameElement);
    return personSearchRequestMessage;
}

From source file:org.ojbc.bundles.adapters.TestStaticMockAdapter.java

private Document buildPersonSearchRequestMessagePersonNameOnly(String systemId) throws Exception {
    File inputFile = new File("src/test/resources/xml/BasePersonSearchRequest.xml");
    Document ret = documentBuilder.parse(new FileInputStream(inputFile));
    Element systemElement = (Element) XmlUtils.xPathNodeSearch(ret.getDocumentElement(),
            "psr:SourceSystemNameText");
    systemElement.setTextContent(systemId);
    Document personSearchRequestMessage = ret;
    Element personElement = (Element) XmlUtils.xPathNodeSearch(personSearchRequestMessage,
            "psr-doc:PersonSearchRequest/psr:Person");
    NodeList children = personElement.getChildNodes();
    int childCount = children.getLength();
    for (int i = childCount - 1; i >= 0; i--) {
        Node child = children.item(i);
        if (!("PersonName".equals(child.getLocalName()))) {
            personElement.removeChild(child);
        }//from  w w w  . j  a v a  2s .co m
    }
    // XmlUtils.printNode(personSearchRequestMessage);
    return personSearchRequestMessage;
}

From source file:org.onehippo.forge.hst.pdf.renderer.HtmlPDFRenderer.java

private static void removeExistingCssLinks(Document document) {
    Element headElem = getFirstChildElement(document.getDocumentElement(), "head");

    if (headElem == null) {
        return;//from w  ww.  ja v a2  s. c  o m
    }

    NodeList nodeList = headElem.getChildNodes();

    if (nodeList != null) {
        int length = nodeList.getLength();

        for (int i = length - 1; i >= 0; i--) {
            Node childNode = nodeList.item(i);

            if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                Element childElem = (Element) childNode;

                if (StringUtils.equalsIgnoreCase("link", childElem.getNodeName())) {
                    if (StringUtils.equalsIgnoreCase("text/css", childElem.getAttribute("type"))) {
                        headElem.removeChild(childElem);
                    }
                }
            }
        }
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Downgrade <new_build> elements to Kyero 2.1.
 * <p>/*w  ww  . j  a  v  a 2  s . c o m*/
 * The &lt;new_build&gt; elements are not available in version 2.1. Instead
 * the value "new_build" is used in the &lt;price_freq&gt; element.
 * <p>
 * Any &lt;new_build&gt; elements are removed. If its value is set to "1",
 * then &lt;price_freq&gt;sale&lt;/price_freq&gt; is convertet to
 * &lt;price_freq&gt;new_build&lt;/price_freq&gt;,
 *
 * @param doc Kyero document in version 3
 * @throws JaxenException
 */
protected void downgradeNewBuildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:new_build", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        String value = StringUtils.trimToNull(node.getTextContent());
        if ("1".equals(value)) {
            Element priceFreqNode = (Element) XmlUtils.newXPath("io:price_freq", doc)
                    .selectSingleNode(parentNode);
            if (priceFreqNode == null) {
                priceFreqNode = doc.createElementNS(KyeroUtils.NAMESPACE, "price_freq");
                priceFreqNode.setTextContent("new_build");
                parentNode.appendChild(priceFreqNode);
            } else if ("sale".equalsIgnoreCase(priceFreqNode.getTextContent())) {
                priceFreqNode.setTextContent("new_build");
            }
        }
        parentNode.removeChild(node);
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Downgrade &lt;url&gt; elements to Kyero 2.1.
 * <p>//from   w w w.j  ava  2 s . c  o  m
 * The &lt;url&gt; elements only support a simple text value in version
 * 2.1. Version 3 allows different URL's for different languages.
 * <p>
 * Any children of &lt;url&gt; elements are removed. The english URL or the
 * first found URL is copied as simple value into the &lt;url&gt; element.
 *
 * @param doc Kyero document in version 3
 * @throws JaxenException
 */
protected void downgradeUrlElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:url", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String enUrlValue = null;
        String fallbackUrlValue = null;
        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Element langNode = (Element) childItem;
            if ("en".equalsIgnoreCase(langNode.getLocalName()))
                enUrlValue = StringUtils.trimToNull(langNode.getTextContent());
            else if (fallbackUrlValue == null)
                fallbackUrlValue = StringUtils.trimToNull(langNode.getTextContent());
            node.removeChild(langNode);
        }

        node.setTextContent((enUrlValue != null) ? enUrlValue : fallbackUrlValue);
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Remove &lt;custom&gt; elements.
 * <p>//from w  ww  .j ava2 s .c  om
 * Kyero 3 does not support &lt;custom&gt; elements in &lt;property&gt; and
 * &lt;agent&gt;.
 * <p>
 * Any occurence of these elements is removed.
 *
 * @param doc OpenImmo document in version 2.1
 * @throws JaxenException
 */
protected void removeCustomElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:custom  | " + "/io:root/io:agent/io:custom", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Remove &lt;energy_rating&gt; elements.
 * <p>/*  www .j  a  va2s .c  o m*/
 * Kyero 2.1 does not support &lt;energy_rating&gt; elements.
 *
 * @param doc OpenImmo document in version 3
 * @throws JaxenException
 */
protected void removeEnergyRatingElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:energy_rating", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}