List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. 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 <new_build> elements are not available in version 2.1. Instead * the value "new_build" is used in the <price_freq> element. * <p> * Any <new_build> elements are removed. If its value is set to "1", * then <price_freq>sale</price_freq> is convertet to * <price_freq>new_build</price_freq>, * * @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 <url> elements to Kyero 2.1. * <p>//from w w w.j ava 2 s . c o m * The <url> elements only support a simple text value in version * 2.1. Version 3 allows different URL's for different languages. * <p> * Any children of <url> elements are removed. The english URL or the * first found URL is copied as simple value into the <url> 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 <custom> elements. * <p>//from w ww .j ava2 s .c om * Kyero 3 does not support <custom> elements in <property> and * <agent>. * <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 <energy_rating> elements. * <p>/* www .j a va2s .c o m*/ * Kyero 2.1 does not support <energy_rating> 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); } }