List of usage examples for org.w3c.dom Node getParentNode
public Node getParentNode();
From source file:eu.transkribus.languageresources.extractor.pagexml.PAGEXMLExtractor.java
public String getTextFromNode(Node unicodeNode) { String textContent = unicodeNode.getTextContent(); Node textLineNode = unicodeNode.getParentNode().getParentNode(); Node customNode = textLineNode.getAttributes().getNamedItem("custom"); String customTagValue = null; if (customNode != null) { customTagValue = textLineNode.getAttributes().getNamedItem("custom").getTextContent(); }/*from w w w . jav a2s . com*/ return getTextFromNode(textContent, customTagValue); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static NodeList getChildElementsByTagName(Element elm, String name) { List<Element> list = new ArrayList<Element>(); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node item = nl.item(c); if (item.getParentNode() == elm && item.getNodeType() == Node.ELEMENT_NODE && name.equals(item.getNodeName())) list.add((Element) item); }//from w ww . java2 s . c o m return new ElementNodeList(list); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static NodeList getChildElementsByTagNameNS(Element elm, String namespaceUri, String localName) { List<Element> list = new ArrayList<Element>(); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node item = nl.item(c); if (item.getParentNode() == elm && item.getNodeType() == Node.ELEMENT_NODE && localName.equals(item.getLocalName()) && namespaceUri.equals(item.getNamespaceURI())) list.add((Element) item); }//from ww w.ja v a2 s . c om return new ElementNodeList(list); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static NodeList getChildElementsOfType(Element elm, SchemaType schemaType) { List<Element> list = new ArrayList<Element>(); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node item = nl.item(c); if (item.getParentNode() == elm && item.getNodeType() == Node.ELEMENT_NODE && ((Element) item) .getAttributeNS(Constants.XSI_NS, "type").endsWith(":" + schemaType.getName().getLocalPart())) { list.add((Element) item); }/*www . j a va 2s . com*/ } return new ElementNodeList(list); }
From source file:eu.transkribus.languageresources.extractor.pagexml.PAGEXMLExtractor.java
private boolean equalsBaseline(Node node1, Node node2) { if (node1 == node2) { return true; }//from w ww . j a va2s . c o m String points1 = getChild(node1.getParentNode().getParentNode(), "Baseline").getAttributes() .getNamedItem("points").getTextContent(); String points2 = getChild(node2.getParentNode().getParentNode(), "Baseline").getAttributes() .getNamedItem("points").getTextContent(); return points1.equals(points2); }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
private Document cropDocumentForNode(Node xmlDoc) throws ParseException { if (xmlDoc.getParentNode() != null) { // if node is not document root node try {/*ww w. j a va2 s . co m*/ Document nodeXmlDoc; synchronized (builder) { nodeXmlDoc = builder.newDocument(); } Node importedNode = nodeXmlDoc.importNode(xmlDoc, true); nodeXmlDoc.appendChild(importedNode); return nodeXmlDoc; } catch (Exception exc) { ParseException pe = new ParseException(StreamsResources.getString( StreamsResources.RESOURCE_BUNDLE_NAME, "ActivityXmlParser.xmlDocument.parse.error"), 0); pe.initCause(exc); throw pe; } } return null; }
From source file:com.photon.phresco.impl.ConfigManagerImpl.java
@Override public void addEnvironments(List<Environment> environments) throws ConfigurationException { // This block will remove all the env node due to modify the order of Environment StringBuilder xpathEnvs = getXpathEnvs(); NodeList nodeList = getNodeList(xpathEnvs.toString()); for (int i = 0; i < nodeList.getLength(); i++) { Node envNode = nodeList.item(i); envNode.getParentNode().removeChild(envNode); }//from w ww .j a v a 2s . c o m createEnvironment(environments, configFile); }
From source file:it.greenvulcano.gvesb.virtual.rest.RestCallOperation.java
@Override public void init(Node node) throws InitializationException { logger.debug("Init start"); try {/* w ww .jav a 2 s . c om*/ name = XMLConfig.get(node, "@name"); String host = XMLConfig.get(node.getParentNode(), "@endpoint"); String uri = XMLConfig.get(node, "@request-uri"); method = XMLConfig.get(node, "@method"); url = host.concat(uri); connectionTimeout = XMLConfig.getInteger(node, "@conn-timeout", 3000); readTimeout = XMLConfig.getInteger(node, "@so-timeout", 6000); Node trustStore = XMLConfig.getNode(node.getParentNode(), "./truststore"); if (Objects.nonNull(trustStore)) { truststorePath = XMLConfig.get(trustStore, "@path"); truststorePassword = XMLConfig.getDecrypted(trustStore, "@password", null); truststoreAlgorithm = XMLConfig.get(trustStore, "@algorithm", null); } Node defaults = XMLConfig.getNode(node.getParentNode(), "./rest-call-defaults"); if (Objects.nonNull(defaults)) { readRestCallConfiguration(defaults); } readRestCallConfiguration(node); logger.debug("init - loaded parameters: url= " + url + " - method= " + method); logger.debug("Init stop"); } catch (Exception exc) { throw new InitializationException("GV_INIT_SERVICE_ERROR", new String[][] { { "message", exc.getMessage() } }, exc); } }
From source file:de.codesourcery.spring.contextrewrite.XMLRewrite.java
private Document parseXML(Resource resource, List<Rule> rules) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { debug("Now loading " + resource); try (InputStream in = resource.getInputStream()) { final Document doc = XMLRewrite.parseXML(in); rewriteXML(doc, rules, false, false); final List<Node> importNodes = evaluateXPath("/beans//import", doc); debug("Found " + importNodes.size() + " import statements"); for (Node importNode : importNodes) { debug("(1) Node has parent: " + importNode.getParentNode()); String path = importNode.getAttributes().getNamedItem("resource").getNodeValue(); if (path.startsWith("classpath:")) { path = path.substring("classpath:".length()); }// w w w . ja v a2 s . c om debug("Including '" + path + "' , now at " + resource); final Resource imported; if (path.startsWith("/")) { // absolute imported = new ClassPathResource(path); } else { imported = resource.createRelative(path); } final Document importedXML = parseXML(imported, rules); mergeAttributes(importedXML.getFirstChild(), doc.getFirstChild(), doc); final List<Node> beans = wrapNodeList(importedXML.getFirstChild().getChildNodes()); for (Node beanNode : beans) { final Node adoptedNode = doc.adoptNode(beanNode.cloneNode(true)); importNode.getParentNode().insertBefore(adoptedNode, importNode); } importNode.getParentNode().removeChild(importNode); } debug("*** return ***"); return doc; } catch (Exception e) { throw new RuntimeException("Failed to load XML from '" + resource + "'", e); } }
From source file:com.dinochiesa.edgecallouts.EditXmlNode.java
private void insertBefore(NodeList nodes, Node newNode, short newNodeType) { Node currentNode = nodes.item(0); switch (newNodeType) { case Node.ATTRIBUTE_NODE: Element parent = ((Attr) currentNode).getOwnerElement(); parent.setAttributeNode((Attr) newNode); break;// ww w. j a v a2s. c om case Node.ELEMENT_NODE: currentNode.getParentNode().insertBefore(newNode, currentNode); break; case Node.TEXT_NODE: String v = currentNode.getNodeValue(); currentNode.setNodeValue(newNode.getNodeValue() + v); break; } }