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.kyero.converters.Kyero_3.java

/**
 * Remove <location> elements.
 * <p>/*from w  w  w.j a v a2 s  .c  o  m*/
 * Kyero 2.1 does not support &lt;location&gt; elements.
 *
 * @param doc OpenImmo document in version 3
 * @throws JaxenException
 */
protected void removeLocationElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:location", 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;notes&gt; elements.
 * <p>//from   www .  j av  a2  s . c o m
 * Kyero 2.1 does not support &lt;notes&gt; elements.
 *
 * @param doc OpenImmo document in version 3
 * @throws JaxenException
 */
protected void removeNotesElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:notes", 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 elements with translations in unsupported languages.
 * <p>/*from   ww w .ja  v a2 s  .c om*/
 * Kyero 2.1 does only support translation in &lt;title&gt; (for images),
 * &lt;desc&gt; (for properties) elements for "en", "es", "de", "nl", "fr".
 *
 * @param doc OpenImmo document in version 3
 * @throws JaxenException
 */
protected void removeUnsupportedLanguageElements(Document doc) throws JaxenException {
    String[] unsupportedLanguages = new String[] { "ar", "bg", "ca", "cs", "da", "el", "et", "fa", "fi", "he",
            "hi", "hu", "id", "it", "ja", "ko", "lt", "lv", "no", "pl", "pt", "ro", "ru", "sk", "sl", "sv",
            "th", "tr", "uk", "vi", "zh", };
    List nodes = XmlUtils
            .newXPath("/io:root/io:property/io:desc | " + "/io:root/io:property/io:images/io:image/io:title",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Element langNode = (Element) childItem;
            String lang = langNode.getLocalName().toLowerCase();
            if (ArrayUtils.contains(unsupportedLanguages, lang)) {
                node.removeChild(langNode);
            }
        }
    }
}

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

/**
 * Upgrade &lt;currency&gt; elements to Kyero 3.
 * <p>//from  w  w w  . ja va  2s  . c o m
 * The &lt;currency&gt; only supports the values "EUR", "GBP", "USD" in
 * version 3.
 * <p>
 * Any &lt;currency&gt; with an unsupported value is removed from the
 * document.
 *
 * @param doc Kyero document in version 2.1
 * @throws JaxenException
 */
protected void upgradeCurrencyElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:currency", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        String value = StringUtils.trimToNull(node.getTextContent());
        if ("EUR".equalsIgnoreCase(value))
            node.setTextContent("EUR");
        else if ("GBP".equalsIgnoreCase(value))
            node.setTextContent("GBP");
        else if ("USD".equalsIgnoreCase(value))
            node.setTextContent("USD");
        else
            parentNode.removeChild(node);
    }
}

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

/**
 * Upgrade &lt;type&gt; elements to Kyero 3.
 * <p>//from ww w  .j ava2s. c om
 * The &lt;type&gt; elements do not support any child element in version 3.
 * <p>
 * Any child elements of &lt;type&gt; are removed. The text from the
 * &lt;en&gt; child element is copied into the &lt;type&gt; element.
 *
 * @param doc Kyero document in version 2.1
 * @throws JaxenException
 */
protected void upgradeTypeElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:type", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

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

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

/**
 * Upgrade &lt;url&gt; elements to Kyero 3.
 * <p>/*from w w w . j a v  a 2 s . co  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>
 * The simple value of &lt;url&gt; elements is removed and copied into the
 * &lt;en&gt; child element.
 *
 * @param doc Kyero document in version 2.1
 * @throws JaxenException
 */
protected void upgradeUrlElements(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 value = StringUtils.trimToNull(node.getTextContent());
        node.setTextContent(null);
        if (value == null) {
            Element parentNode = (Element) node.getParentNode();
            parentNode.removeChild(node);
        } else {
            Element childNode = doc.createElementNS(KyeroUtils.NAMESPACE, "en");
            childNode.setTextContent(value);
            node.appendChild(childNode);
        }
    }
}

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

/**
 * Remove unsupported children from all &lt;anbieter&gt; elements.
 * <p>//from  ww w .  j a  v  a2 s.c om
 * OpenImmo 1.1 does not support the following children for
 * &lt;anbieter&gt; elements: &lt;lizenzkennung&gt;, &lt;impressum_strukt&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeAnbieterChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:lizenzkennung | " + "/io:openimmo/io:anbieter/io:impressum_strukt",
            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;ausstattung&gt; elements.
 * <p>/* w w  w. ja v  a 2 s . co  m*/
 * OpenImmo 1.1 does not support the following children for
 * &lt;ausstattung&gt; elements: &lt;dvbt&gt;, &lt;breitband_zugang&gt;,
 * &lt;umts_empfang&gt;, &lt;abstellraum&gt;, &lt;fahrradraum&gt;,
 * &lt;rolladen&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeAusstattungChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:dvbt | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:breitband_zugang | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:umts_empfang | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:abstellraum | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:fahrradraum | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:rolladen", 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;bewertung&gt; elements.
 * <p>/*from w  w  w .  jav  a 2  s  .  com*/
 * OpenImmo 1.1 does not support &lt;bewertung&gt; elements.
 * <p>
 * Any occurences of these elements are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeBewertungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:bewertung", 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;bieterverfahren&gt; elements.
 * <p>/* ww w.jav a2s .co  m*/
 * OpenImmo 1.1 does not support &lt;bieterverfahren&gt; elements.
 * <p>
 * Any occurences of these elements are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void removeBieterverfahrenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:bieterverfahren", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}