org.dom4j.Node.getNodeType()方法的使用及代码示例

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

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

Node.getNodeType介绍

[英]Returns the code according to the type of node. This makes processing nodes polymorphically much easier as the switch statement can be used instead of multiple if (instanceof) statements.
[中]根据节点类型返回代码。由于可以使用switch语句代替多个if(instanceof)语句,这使得多态处理节点变得更加容易。

代码示例

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

  1. public short getNodeType(Object node)
  2. {
  3. if ( node instanceof Node )
  4. {
  5. return ((Node) node).getNodeType();
  6. }
  7. return 0;
  8. }

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

  1. @Override
  2. String getType(Object node) {
  3. switch(((Node) node).getNodeType()) {
  4. case Node.ATTRIBUTE_NODE: {
  5. return "attribute";

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

  1. public boolean matches(Node node) {
  2. return node.getNodeType() == nodeType;
  3. }

代码示例来源:origin: igniterealtime/Openfire

  1. protected void writeNode(Node node) throws IOException {
  2. int nodeType = node.getNodeType();
  3. switch (nodeType) {
  4. case Node.ELEMENT_NODE:

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

  1. /**
  2. * DOCUMENT ME!
  3. *
  4. * @param content
  5. * DOCUMENT ME!
  6. *
  7. * @return the text value of the given content object as text which returns
  8. * the text value of CDATA, Entity or Text nodes
  9. */
  10. protected String getContentAsText(Object content) {
  11. if (content instanceof Node) {
  12. Node node = (Node) content;
  13. switch (node.getNodeType()) {
  14. case CDATA_SECTION_NODE:
  15. // case ENTITY_NODE:
  16. case ENTITY_REFERENCE_NODE:
  17. case TEXT_NODE:
  18. return node.getText();
  19. default:
  20. break;
  21. }
  22. } else if (content instanceof String) {
  23. return (String) content;
  24. }
  25. return "";
  26. }

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

  1. /**
  2. * DOCUMENT ME!
  3. *
  4. * @param content
  5. * DOCUMENT ME!
  6. *
  7. * @return the XPath defined string-value of the given content object
  8. */
  9. protected String getContentAsStringValue(Object content) {
  10. if (content instanceof Node) {
  11. Node node = (Node) content;
  12. switch (node.getNodeType()) {
  13. case CDATA_SECTION_NODE:
  14. // case ENTITY_NODE:
  15. case ENTITY_REFERENCE_NODE:
  16. case TEXT_NODE:
  17. case ELEMENT_NODE:
  18. return node.getStringValue();
  19. default:
  20. break;
  21. }
  22. } else if (content instanceof String) {
  23. return (String) content;
  24. }
  25. return "";
  26. }

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

  1. public void setText(String text) {
  2. /* remove all text nodes */
  3. List<Node> allContent = contentList();
  4. if (allContent != null) {
  5. Iterator<Node> it = allContent.iterator();
  6. while (it.hasNext()) {
  7. Node node = it.next();
  8. switch (node.getNodeType()) {
  9. case CDATA_SECTION_NODE:
  10. // case ENTITY_NODE:
  11. case ENTITY_REFERENCE_NODE:
  12. case TEXT_NODE:
  13. it.remove();
  14. default:
  15. break;
  16. }
  17. }
  18. }
  19. addText(text);
  20. }

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

  1. public boolean remove(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. return remove((Element) node);
  5. case COMMENT_NODE:
  6. return remove((Comment) node);
  7. case PROCESSING_INSTRUCTION_NODE:
  8. return remove((ProcessingInstruction) node);
  9. default:
  10. invalidNodeTypeAddException(node);
  11. return false;
  12. }
  13. }

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

  1. public void add(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. add((Element) node);
  5. break;
  6. case COMMENT_NODE:
  7. add((Comment) node);
  8. break;
  9. case PROCESSING_INSTRUCTION_NODE:
  10. add((ProcessingInstruction) node);
  11. break;
  12. default:
  13. invalidNodeTypeAddException(node);
  14. }
  15. }

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

  1. int matchType = node.getNodeType();

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

  1. public int compare(Node n1, Node n2) {
  2. int nodeType1 = n1.getNodeType();
  3. int nodeType2 = n2.getNodeType();
  4. int answer = nodeType1 - nodeType2;

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

  1. protected void writeNode(Node node) throws IOException {
  2. int nodeType = node.getNodeType();

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

  1. public boolean remove(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. return remove((Element) node);
  5. case ATTRIBUTE_NODE:
  6. return remove((Attribute) node);
  7. case TEXT_NODE:
  8. return remove((Text) node);
  9. case CDATA_SECTION_NODE:
  10. return remove((CDATA) node);
  11. case ENTITY_REFERENCE_NODE:
  12. return remove((Entity) node);
  13. case PROCESSING_INSTRUCTION_NODE:
  14. return remove((ProcessingInstruction) node);
  15. case COMMENT_NODE:
  16. return remove((Comment) node);
  17. /*
  18. * case DOCUMENT_TYPE_NODE: return remove((DocumentType) node);
  19. */
  20. case NAMESPACE_NODE:
  21. return remove((Namespace) node);
  22. default:
  23. return false;
  24. }
  25. }

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

  1. switch (n.getNodeType()) {
  2. case Node.ELEMENT_NODE:
  3. writeElement((Element) n);

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

  1. int nodeType = node.getNodeType();

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

  1. public void add(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. add((Element) node);

代码示例来源:origin: com.github.jjYBdx4IL.utils/xml-dom4j-utils

  1. public static boolean hasNonTextChilds(Element element) {
  2. for (Object node : element.content()) {
  3. Node e1 = (Node) node;
  4. if (e1.getNodeType() != Node.TEXT_NODE) {
  5. return true;
  6. }
  7. }
  8. return false;
  9. }

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

  1. public void testBug926713() throws Exception {
  2. Document doc = getDocument("/xml/test/cdata.xml");
  3. Element foo = doc.getRootElement();
  4. Element bar = foo.element("bar");
  5. List content = bar.content();
  6. assertEquals(3, content.size());
  7. assertEquals(Node.TEXT_NODE, ((Node) content.get(0)).getNodeType());
  8. assertEquals(Node.CDATA_SECTION_NODE, ((Node) content.get(1))
  9. .getNodeType());
  10. assertEquals(Node.TEXT_NODE, ((Node) content.get(2)).getNodeType());
  11. }
  12. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j

  1. public boolean remove(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. return remove((Element) node);
  5. case COMMENT_NODE:
  6. return remove((Comment) node);
  7. case PROCESSING_INSTRUCTION_NODE:
  8. return remove((ProcessingInstruction) node);
  9. default:
  10. invalidNodeTypeAddException(node);
  11. return false;
  12. }
  13. }

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

  1. public boolean remove(Node node) {
  2. switch (node.getNodeType()) {
  3. case ELEMENT_NODE:
  4. return remove((Element) node);
  5. case COMMENT_NODE:
  6. return remove((Comment) node);
  7. case PROCESSING_INSTRUCTION_NODE:
  8. return remove((ProcessingInstruction) node);
  9. default:
  10. invalidNodeTypeAddException(node);
  11. return false;
  12. }
  13. }

相关文章