org.w3c.dom.Node.getNextSibling()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(439)

本文整理了Java中org.w3c.dom.Node.getNextSibling()方法的一些代码示例,展示了Node.getNextSibling()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getNextSibling()方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:getNextSibling

Node.getNextSibling介绍

[英]The node immediately following this node. If there is no such node, this returns null.
[中]紧跟在此节点之后的节点。如果没有这样的节点,则返回null

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

  1. private Element findFirstChildElement(Element parent) {
  2. Node ret = parent.getFirstChild();
  3. while (ret != null && (!(ret instanceof Element))) {
  4. ret = ret.getNextSibling();
  5. }
  6. return (Element) ret;
  7. }

代码示例来源:origin: plutext/docx4j

  1. public static Element getNextElement(Node el) {
  2. Node node = el;
  3. while (node != null && node.getNodeType() != Node.ELEMENT_NODE) {
  4. node = node.getNextSibling();
  5. }
  6. return (Element)node;
  7. }

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

  1. private Element findChildElement(Element parent, String name) {
  2. if (parent == null) {
  3. return null;
  4. }
  5. Node ret = parent.getFirstChild();
  6. while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name))) {
  7. ret = ret.getNextSibling();
  8. }
  9. return (Element) ret;
  10. }

代码示例来源:origin: oracle/opengrok

  1. private String getValue(Node node) {
  2. if (node == null) {
  3. return null;
  4. }
  5. StringBuilder sb = new StringBuilder();
  6. Node n = node.getFirstChild();
  7. while (n != null) {
  8. if (n.getNodeType() == Node.TEXT_NODE) {
  9. sb.append(n.getNodeValue());
  10. }
  11. n = n.getNextSibling();
  12. }
  13. return sb.toString();
  14. }

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

  1. BeanDefinitionBuilder bean
  2. ) {
  3. Node n = parent.getFirstChild();
  4. while (n != null) {
  5. if (Node.ELEMENT_NODE != n.getNodeType()
  6. || !HTTP_NS.equals(n.getNamespaceURI())) {
  7. n = n.getNextSibling();
  8. continue;
  9. String elementName = n.getLocalName();
  10. mapTLSClientParameters((Element)n, bean);
  11. n = n.getNextSibling();

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * Recursively removes all comment nodes from the subtree.
  3. *
  4. * @see #simplify
  5. */
  6. static public void removeComments(Node parent) {
  7. Node child = parent.getFirstChild();
  8. while (child != null) {
  9. Node nextSibling = child.getNextSibling();
  10. if (child.getNodeType() == Node.COMMENT_NODE) {
  11. parent.removeChild(child);
  12. } else if (child.hasChildNodes()) {
  13. removeComments(child);
  14. }
  15. child = nextSibling;
  16. }
  17. }

代码示例来源:origin: kiegroup/jbpm

  1. protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeInputAssociation) {
  2. // sourceRef
  3. org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  4. if ("sourceRef".equals(subNode.getNodeName())) {
  5. String source = subNode.getTextContent();
  6. // targetRef
  7. subNode = subNode.getNextSibling();
  8. String target = subNode.getTextContent();
  9. forEachNodeInputAssociation.put(target, source);
  10. }
  11. }

代码示例来源:origin: marytts/marytts

  1. /**
  2. * Get the first child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return n
  7. */
  8. public static Element getFirstChildElement(Element e) {
  9. Node n = e.getFirstChild();
  10. while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
  11. n = n.getNextSibling();
  12. }
  13. // Now n is either null or an Element
  14. return (Element) n;
  15. }

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. private String getComplexTypeNameFromChildren(Node localComplexTypeRootNode,
  2. String elementNameWithoutNamespace) {
  3. if(localComplexTypeRootNode == null) {
  4. return "";
  5. }
  6. Node node = localComplexTypeRootNode.getFirstChild();
  7. String complexTypeName = "";
  8. while (node != null) {
  9. if ( node instanceof Element && "element".equals(node.getLocalName())) {
  10. Node nameAttribute = getNameOrRefElement(node);
  11. if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
  12. Node complexTypeAttribute = node.getAttributes().getNamedItem("type");
  13. if (complexTypeAttribute!=null) {
  14. complexTypeName = complexTypeAttribute.getNodeValue();
  15. break;
  16. }
  17. }
  18. }
  19. node = node.getNextSibling();
  20. }
  21. return complexTypeName;
  22. }

代码示例来源:origin: libgdx/libgdx

  1. private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException {
  2. Document doc;
  3. DocumentBuilder docBuilder;
  4. DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  5. try {
  6. docBuilder = docFactory.newDocumentBuilder();
  7. doc = docBuilder.parse(tmxFileHandle.read());
  8. Node map = doc.getFirstChild();
  9. while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") {
  10. if ((map = map.getNextSibling()) == null) {
  11. throw new GdxRuntimeException("Couldn't find map node!");
  12. }
  13. }
  14. setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas");
  15. TransformerFactory transformerFactory = TransformerFactory.newInstance();
  16. Transformer transformer = transformerFactory.newTransformer();
  17. DOMSource source = new DOMSource(doc);
  18. outputDir.mkdirs();
  19. StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name()));
  20. transformer.transform(source, result);
  21. } catch (ParserConfigurationException e) {
  22. throw new RuntimeException("ParserConfigurationException: " + e.getMessage());
  23. } catch (SAXException e) {
  24. throw new RuntimeException("SAXException: " + e.getMessage());
  25. } catch (TransformerConfigurationException e) {
  26. throw new RuntimeException("TransformerConfigurationException: " + e.getMessage());
  27. } catch (TransformerException e) {
  28. throw new RuntimeException("TransformerException: " + e.getMessage());
  29. }
  30. }

代码示例来源:origin: kiegroup/jbpm

  1. protected void handleStateNode(final Node node, final Element element,
  2. final String uri, final String localName,
  3. final ExtensibleXmlParser parser) throws SAXException {
  4. super.handleNode(node, element, uri, localName, parser);
  5. StateNode stateNode = (StateNode) node;
  6. org.w3c.dom.Node xmlNode = element.getFirstChild();
  7. while (xmlNode != null) {
  8. String nodeName = xmlNode.getNodeName();
  9. if ("conditionalEventDefinition".equals(nodeName)) {
  10. org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  11. while (subNode != null) {
  12. String subnodeName = subNode.getNodeName();
  13. if ("condition".equals(subnodeName)) {
  14. stateNode.setMetaData("Condition",
  15. xmlNode.getTextContent());
  16. break;
  17. }
  18. subNode = subNode.getNextSibling();
  19. }
  20. }
  21. xmlNode = xmlNode.getNextSibling();
  22. }
  23. }

代码示例来源:origin: plantuml/plantuml

  1. private String displayMetadata(Node node, int level) {
  2. final NamedNodeMap map = node.getAttributes();
  3. if (map != null) {
  4. final Node keyword = map.getNamedItem("keyword");
  5. if (keyword != null && tag.equals(keyword.getNodeValue())) {
  6. final Node text = map.getNamedItem("value");
  7. if (text != null) {
  8. return text.getNodeValue();
  9. }
  10. }
  11. }
  12. Node child = node.getFirstChild();
  13. // children, so close current tag
  14. while (child != null) {
  15. // print children recursively
  16. final String result = displayMetadata(child, level + 1);
  17. if (result != null) {
  18. return result;
  19. }
  20. child = child.getNextSibling();
  21. }
  22. return null;
  23. }

代码示例来源:origin: groovy/groovy-core

  1. protected void printChildren(Node parent, Map namespaces) {
  2. for (Node node = parent.getFirstChild(); node != null; node = node.getNextSibling()) {
  3. print(node, namespaces, false);
  4. }
  5. }

代码示例来源:origin: loklak/loklak_server

  1. private static JSONObject convertDOMNodeToMap(Node node) {
  2. Node directChild = node.getFirstChild();
  3. if (directChild == null) {
  4. return null;
  5. }
  6. JSONObject result = new JSONObject(true);
  7. while (directChild != null) {
  8. if (directChild.getChildNodes().getLength() == 1
  9. && directChild.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE) {
  10. result.put(directChild.getNodeName(), directChild.getChildNodes().item(0).getTextContent());
  11. } else {
  12. result.put(directChild.getNodeName(), convertDOMNodeToMap(directChild));
  13. }
  14. directChild = directChild.getNextSibling();
  15. }
  16. return result;
  17. }

代码示例来源:origin: jamesagnew/hapi-fhir

  1. private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError {
  2. XhtmlNode res = new XhtmlNode(NodeType.Element);
  3. res.setName(node.getLocalName());
  4. defaultNS = checkNS(res, node, defaultNS);
  5. for (int i = 0; i < node.getAttributes().getLength(); i++) {
  6. Attr attr = (Attr) node.getAttributes().item(i);
  7. if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns"))
  8. res.getAttributes().put(attr.getName(), attr.getValue());
  9. }
  10. Node child = node.getFirstChild();
  11. while (child != null) {
  12. if (child.getNodeType() == Node.TEXT_NODE) {
  13. res.addText(child.getTextContent());
  14. } else if (child.getNodeType() == Node.COMMENT_NODE) {
  15. res.addComment(child.getTextContent());
  16. } else if (child.getNodeType() == Node.ELEMENT_NODE) {
  17. if (elementIsOk(child.getLocalName()))
  18. res.getChildNodes().add(parseNode((Element) child, defaultNS));
  19. } else
  20. throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc());
  21. child = child.getNextSibling();
  22. }
  23. return res;
  24. }

代码示例来源:origin: kiegroup/jbpm

  1. protected void handleForEachNode(final Node node, final Element element, final String uri,
  2. final String localName, final ExtensibleXmlParser parser) throws SAXException {
  3. ForEachNode forEachNode = (ForEachNode) node;
  4. org.w3c.dom.Node xmlNode = element.getFirstChild();
  5. while (xmlNode != null) {
  6. String nodeName = xmlNode.getNodeName();
  7. if ("dataInputAssociation".equals(nodeName)) {
  8. readDataInputAssociation(xmlNode, inputAssociation);
  9. } else if ("dataOutputAssociation".equals(nodeName)) {
  10. readDataOutputAssociation(xmlNode, outputAssociation);
  11. } else if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
  12. readMultiInstanceLoopCharacteristics(xmlNode, forEachNode, parser);
  13. }
  14. xmlNode = xmlNode.getNextSibling();
  15. }
  16. }

代码示例来源:origin: org.freemarker/freemarker

  1. /**
  2. * Recursively removes all processing instruction nodes from the subtree.
  3. *
  4. * @see #simplify
  5. */
  6. static public void removePIs(Node parent) {
  7. Node child = parent.getFirstChild();
  8. while (child != null) {
  9. Node nextSibling = child.getNextSibling();
  10. if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
  11. parent.removeChild(child);
  12. } else if (child.hasChildNodes()) {
  13. removePIs(child);
  14. }
  15. child = nextSibling;
  16. }
  17. }

代码示例来源:origin: kiegroup/jbpm

  1. protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeOutputAssociation) {
  2. // sourceRef
  3. org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  4. if ("sourceRef".equals(subNode.getNodeName())) {
  5. String source = subNode.getTextContent();
  6. // targetRef
  7. subNode = subNode.getNextSibling();
  8. String target = subNode.getTextContent();
  9. forEachNodeOutputAssociation.put(source, target);
  10. }
  11. }

代码示例来源:origin: marytts/marytts

  1. /**
  2. * Get the first child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
  3. *
  4. * @param e
  5. * e
  6. * @return n
  7. */
  8. public static Element getFirstChildElement(Element e) {
  9. Node n = e.getFirstChild();
  10. while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
  11. n = n.getNextSibling();
  12. }
  13. // Now n is either null or an Element
  14. return (Element) n;
  15. }

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
  2. String complexTypeName) {
  3. Node node = xmlSchema.getFirstChild();
  4. while (node != null) {
  5. if ( node instanceof Element) {
  6. if ("complexType".equals(node.getLocalName())) {
  7. Node nameAttribute = getNameOrRefElement(node);
  8. if (nameAttribute.getNodeValue().equals(complexTypeName)) {
  9. Node sequence = node.getFirstChild();
  10. while(sequence != null) {
  11. final String localName = sequence.getLocalName();
  12. if ("sequence".equals(localName) || "all".equals(localName)) {
  13. complexTypeNode = sequence;
  14. sequence = sequence.getNextSibling();
  15. node = node.getNextSibling();

相关文章