private Element findFirstChildElement(Element parent) { Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element))) { ret = ret.getNextSibling(); } return (Element) ret; }
public static Element getNextElement(Node el) { Node node = el; while (node != null && node.getNodeType() != Node.ELEMENT_NODE) { node = node.getNextSibling(); } return (Element)node; }
private Element findChildElement(Element parent, String name) { if (parent == null) { return null; } Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name))) { ret = ret.getNextSibling(); } return (Element) ret; }
private String getValue(Node node) { if (node == null) { return null; } StringBuilder sb = new StringBuilder(); Node n = node.getFirstChild(); while (n != null) { if (n.getNodeType() == Node.TEXT_NODE) { sb.append(n.getNodeValue()); } n = n.getNextSibling(); } return sb.toString(); }
BeanDefinitionBuilder bean ) { Node n = parent.getFirstChild(); while (n != null) { if (Node.ELEMENT_NODE != n.getNodeType() || !HTTP_NS.equals(n.getNamespaceURI())) { n = n.getNextSibling(); continue; String elementName = n.getLocalName(); mapTLSClientParameters((Element)n, bean); n = n.getNextSibling();
/** * Recursively removes all comment nodes from the subtree. * * @see #simplify */ static public void removeComments(Node parent) { Node child = parent.getFirstChild(); while (child != null) { Node nextSibling = child.getNextSibling(); if (child.getNodeType() == Node.COMMENT_NODE) { parent.removeChild(child); } else if (child.hasChildNodes()) { removeComments(child); } child = nextSibling; } }
protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeInputAssociation) { // sourceRef org.w3c.dom.Node subNode = xmlNode.getFirstChild(); if ("sourceRef".equals(subNode.getNodeName())) { String source = subNode.getTextContent(); // targetRef subNode = subNode.getNextSibling(); String target = subNode.getTextContent(); forEachNodeInputAssociation.put(target, source); } }
/** * Get the first child of <code>e</code> which is an element, or <code>null</code> if there is no such element. * * @param e * e * @return n */ public static Element getFirstChildElement(Element e) { Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } // Now n is either null or an Element return (Element) n; }
private String getComplexTypeNameFromChildren(Node localComplexTypeRootNode, String elementNameWithoutNamespace) { if(localComplexTypeRootNode == null) { return ""; } Node node = localComplexTypeRootNode.getFirstChild(); String complexTypeName = ""; while (node != null) { if ( node instanceof Element && "element".equals(node.getLocalName())) { Node nameAttribute = getNameOrRefElement(node); if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) { Node complexTypeAttribute = node.getAttributes().getNamedItem("type"); if (complexTypeAttribute!=null) { complexTypeName = complexTypeAttribute.getNodeValue(); break; } } } node = node.getNextSibling(); } return complexTypeName; }
private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException { Document doc; DocumentBuilder docBuilder; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); try { docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(tmxFileHandle.read()); Node map = doc.getFirstChild(); while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") { if ((map = map.getNextSibling()) == null) { throw new GdxRuntimeException("Couldn't find map node!"); } } setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas"); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); outputDir.mkdirs(); StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name())); transformer.transform(source, result); } catch (ParserConfigurationException e) { throw new RuntimeException("ParserConfigurationException: " + e.getMessage()); } catch (SAXException e) { throw new RuntimeException("SAXException: " + e.getMessage()); } catch (TransformerConfigurationException e) { throw new RuntimeException("TransformerConfigurationException: " + e.getMessage()); } catch (TransformerException e) { throw new RuntimeException("TransformerException: " + e.getMessage()); } }
protected void handleStateNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { super.handleNode(node, element, uri, localName, parser); StateNode stateNode = (StateNode) node; org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("conditionalEventDefinition".equals(nodeName)) { org.w3c.dom.Node subNode = xmlNode.getFirstChild(); while (subNode != null) { String subnodeName = subNode.getNodeName(); if ("condition".equals(subnodeName)) { stateNode.setMetaData("Condition", xmlNode.getTextContent()); break; } subNode = subNode.getNextSibling(); } } xmlNode = xmlNode.getNextSibling(); } }
private String displayMetadata(Node node, int level) { final NamedNodeMap map = node.getAttributes(); if (map != null) { final Node keyword = map.getNamedItem("keyword"); if (keyword != null && tag.equals(keyword.getNodeValue())) { final Node text = map.getNamedItem("value"); if (text != null) { return text.getNodeValue(); } } } Node child = node.getFirstChild(); // children, so close current tag while (child != null) { // print children recursively final String result = displayMetadata(child, level + 1); if (result != null) { return result; } child = child.getNextSibling(); } return null; }
protected void printChildren(Node parent, Map namespaces) { for (Node node = parent.getFirstChild(); node != null; node = node.getNextSibling()) { print(node, namespaces, false); } }
private static JSONObject convertDOMNodeToMap(Node node) { Node directChild = node.getFirstChild(); if (directChild == null) { return null; } JSONObject result = new JSONObject(true); while (directChild != null) { if (directChild.getChildNodes().getLength() == 1 && directChild.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) { result.put(directChild.getNodeName(), directChild.getChildNodes().item(0).getTextContent()); } else { result.put(directChild.getNodeName(), convertDOMNodeToMap(directChild)); } directChild = directChild.getNextSibling(); } return result; }
private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError { XhtmlNode res = new XhtmlNode(NodeType.Element); res.setName(node.getLocalName()); defaultNS = checkNS(res, node, defaultNS); for (int i = 0; i < node.getAttributes().getLength(); i++) { Attr attr = (Attr) node.getAttributes().item(i); if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns")) res.getAttributes().put(attr.getName(), attr.getValue()); } Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { res.addText(child.getTextContent()); } else if (child.getNodeType() == Node.COMMENT_NODE) { res.addComment(child.getTextContent()); } else if (child.getNodeType() == Node.ELEMENT_NODE) { if (elementIsOk(child.getLocalName())) res.getChildNodes().add(parseNode((Element) child, defaultNS)); } else throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc()); child = child.getNextSibling(); } return res; }
protected void handleForEachNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException { ForEachNode forEachNode = (ForEachNode) node; org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("dataInputAssociation".equals(nodeName)) { readDataInputAssociation(xmlNode, inputAssociation); } else if ("dataOutputAssociation".equals(nodeName)) { readDataOutputAssociation(xmlNode, outputAssociation); } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) { readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser); } xmlNode = xmlNode.getNextSibling(); } }
/** * Recursively removes all processing instruction nodes from the subtree. * * @see #simplify */ static public void removePIs(Node parent) { Node child = parent.getFirstChild(); while (child != null) { Node nextSibling = child.getNextSibling(); if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { parent.removeChild(child); } else if (child.hasChildNodes()) { removePIs(child); } child = nextSibling; } }
protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeOutputAssociation) { // sourceRef org.w3c.dom.Node subNode = xmlNode.getFirstChild(); if ("sourceRef".equals(subNode.getNodeName())) { String source = subNode.getTextContent(); // targetRef subNode = subNode.getNextSibling(); String target = subNode.getTextContent(); forEachNodeOutputAssociation.put(source, target); } }
/** * Get the first child of <code>e</code> which is an element, or <code>null</code> if there is no such element. * * @param e * e * @return n */ public static Element getFirstChildElement(Element e) { Node n = e.getFirstChild(); while (n != null && n.getNodeType() != Node.ELEMENT_NODE) { n = n.getNextSibling(); } // Now n is either null or an Element return (Element) n; }
private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode, String complexTypeName) { Node node = xmlSchema.getFirstChild(); while (node != null) { if ( node instanceof Element) { if ("complexType".equals(node.getLocalName())) { Node nameAttribute = getNameOrRefElement(node); if (nameAttribute.getNodeValue().equals(complexTypeName)) { Node sequence = node.getFirstChild(); while(sequence != null) { final String localName = sequence.getLocalName(); if ("sequence".equals(localName) || "all".equals(localName)) { complexTypeNode = sequence; sequence = sequence.getNextSibling(); node = node.getNextSibling();