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.openestate.io.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Remove <energiepass> elements.
 * <p>/*w w w .  ja v a  2  s.  com*/
 * OpenImmo 1.1 does not support &lt;energiepass&gt; elements.
 * <p>
 * Any occurences of these elements are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeEnergiepassElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass", 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.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Remove unsupported children from all &lt;geo&gt; elements.
 * <p>/*from   ww  w .  j  a va2  s  .  c o  m*/
 * OpenImmo 1.1 does not support the following children for
 * &lt;geo&gt; elements: &lt;anzahl_etagen&gt;, &lt;karten_makro&gt;,
 * &lt;karten_mikro&gt;, &lt;virtuelletour&gt;, &lt;luftbildern&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeGeoChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:geo/io:anzahl_etagen | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:geo/io:karten_makro | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:geo/io:karten_mikro | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:geo/io:virtuelletour | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:geo/io:luftbildern", 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.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Remove &lt;heizkosten_enthalten&gt; elements.
 * <p>//from   w  ww  .  j  ava2  s. com
 * OpenImmo 1.1 does not support &lt;heizkosten_enthalten&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeHeizkostenEnthaltenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:preise/io:heizkosten_enthalten", 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.openimmo.converters.OpenImmo_1_2_0.java

/**
 * Remove &lt;user_defined_extend&gt; elements.
 * <p>/*from w w  w . j av a 2 s  .  c o m*/
 * OpenImmo 1.1 does not support &lt;user_defined_extend&gt; elements .
 * <p>
 * Any occurences of these elements are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeUserDefinedExtendElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("//io:user_defined_extend", 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.openimmo.converters.OpenImmo_1_2_1.java

/**
 * Remove &lt;objektart_zusatz&gt; elements.
 * <p>/*from w  w w  .j  av  a2s .c  o  m*/
 * OpenImmo 1.2.0 does not support &lt;objektart_zusatz&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.1
 * @throws JaxenException
 */
protected void removeObjektartZusatzElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:objektart_zusatz", 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.openimmo.converters.OpenImmo_1_2_2.java

/**
 * Downgrade &lt;objektart&gt; elements to OpenImmo 1.2.1.
 * <p>/*from w  ww.j  a v  a2 s .c  o m*/
 * The &lt;objektart&gt; element does only allow the same type of child
 * element in version 1.2.1.
 * <p>
 * Any child type, that differs from the first child type, is removed.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void downgradeObjektartElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element parentNode = (Element) item;
        String type = null;

        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Element node = (Element) childItem;
            if (type == null) {
                //LOGGER.debug( "PRIMARY TYPE: " + node.getLocalName() );
                type = node.getLocalName();
            } else if (!type.equalsIgnoreCase(node.getLocalName())) {
                //LOGGER.debug( "REMOVE SECONDARY TYPE: " + node.getLocalName() );
                parentNode.removeChild(node);
            }
        }
    }
}

From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_2.java

/**
 * Remove unsupported children from all &lt;ausstattung&gt; elements.
 * <p>/*w  w  w . j a v a 2 s  .c  o  m*/
 * OpenImmo 1.2.1 does not support the following children for
 * &lt;ausstattung&gt; elements: &lt;ausstatt_kategorie&gt;, &lt;dachform&gt;,
 * &lt;bauweise&gt;, &lt;ausbaustufe&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void removeAusstattungChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausstatt_kategorie | "
                    + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:dachform | "
                    + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:bauweise | "
                    + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:ausbaustufe", 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.openimmo.converters.OpenImmo_1_2_2.java

/**
 * Remove &lt;provisionspflichtig&gt; elements.
 * <p>//from   w w w. java2s . c o  m
 * OpenImmo 1.2.1 does not support &lt;provisionspflichtig&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void removeProvisionspflichtigElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:preise/io:provisionspflichtig", 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.openimmo.converters.OpenImmo_1_2_2.java

/**
 * Remove &lt;versteigerung&gt; elements.
 * <p>/*from w w  w.j  av a2s  . co  m*/
 * OpenImmo 1.2.1 does not support &lt;versteigerung&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void removeVersteigerungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:versteigerung", 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.openimmo.converters.OpenImmo_1_2_3.java

/**
 * Remove unsupported children from all &lt;flaechen&gt; elements.
 * <p>//from  w w  w.  j  a  v  a2 s. c  om
 * OpenImmo 1.2.2 does not support the following children for
 * &lt;flaechen&gt; elements: &lt;anzahl_balkone&gt;, &lt;anzahl_terrassen&gt;
 * <p>
 * These elements are removed by this function. If
 * &lt;anzahl_balkon_terrassen&gt; is not already specified, the sum values of
 * &lt;anzahl_balkone&gt; and &lt;anzahl_terrassen&gt; are written into
 * &lt;anzahl_balkon_terrassen&gt;.
 *
 * @param doc OpenImmo document in version 1.2.3
 * @throws JaxenException
 */
protected void downgradeFlaechenChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:flaechen", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element parentNode = (Element) item;
        boolean passedAnzahlBalkone = false;
        boolean passedAnzahlTerrassen = false;
        double sum = 0;

        List childNodes = XmlUtils.newXPath("io:anzahl_balkone", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Node node = (Node) childItem;
            if (!passedAnzahlBalkone) {
                passedAnzahlBalkone = true;
                String value = StringUtils.trimToNull(node.getTextContent());
                try {
                    sum += (value != null) ? Double.parseDouble(value) : 0;
                } catch (NumberFormatException ex) {
                    LOGGER.warn(
                            "Can't parse <anzahl_balkone>" + value + "</anzahl_balkone> into a numeric value!");
                    LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
                }
            }
            parentNode.removeChild(node);
        }

        childNodes = XmlUtils.newXPath("io:anzahl_terrassen", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Node node = (Node) childItem;
            if (!passedAnzahlTerrassen) {
                passedAnzahlTerrassen = true;
                String value = StringUtils.trimToNull(node.getTextContent());
                try {
                    sum += (value != null) ? Double.parseDouble(value) : 0;
                } catch (NumberFormatException ex) {
                    LOGGER.warn("Can't parse <anzahl_terrassen>" + value
                            + "</anzahl_terrassen> into a numeric value!");
                    LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
                }
            }
            parentNode.removeChild(node);
        }

        if (sum > 0) {
            Element node = (Element) XmlUtils.newXPath("io:anzahl_balkon_terrassen", doc)
                    .selectSingleNode(parentNode);
            if (node == null) {
                node = doc.createElementNS(StringUtils.EMPTY, "anzahl_balkon_terrassen");
                node.setTextContent(String.valueOf(sum));
                parentNode.appendChild(node);
            } else if (StringUtils.isBlank(node.getTextContent())) {
                node.setTextContent(String.valueOf(sum));
            }
        }
    }
}