List of usage examples for org.dom4j Node ELEMENT_NODE
short ELEMENT_NODE
To view the source code for org.dom4j Node ELEMENT_NODE.
Click Source Link
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Removes the elements and text inside the given element, but not the attributes or namespace * declarations on the element.//w w w . j a v a 2s .c o m */ public static void clearElementContent(final Element elt) { final java.util.List cntnt = elt.content(); for (final java.util.ListIterator j = cntnt.listIterator(); j.hasNext();) { final Node chld = (Node) j.next(); if (chld.getNodeType() == Node.TEXT_NODE || chld.getNodeType() == Node.ELEMENT_NODE) { j.remove(); } } }
From source file:org.pentaho.platform.config.PentahoXml.java
License:Open Source License
public List<AclEntry> getDefaultAcls() { List<AclEntry> aclEntries = new ArrayList<>(); List<Node> nodes = document.selectNodes(ACL_ENTRY_XPATH); //$NON-NLS-1$ //$NON-NLS-2$ for (Node node : nodes) { if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; AclEntry aclEntry = new AclEntry(); aclEntry.setPrincipalName(element.attributeValue("role")); aclEntry.setPermission(element.attributeValue("acl")); aclEntries.add(aclEntry);/*from w w w . j a v a 2 s . c o m*/ } } return aclEntries; }
From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, EvaluationHelper evaluationHelper, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException, EvaluationException { // Use default template content for (Iterator<Node> i = element.nodeIterator(); i.hasNext();) { Node node = i.next();/*from w ww. ja va2 s.c o m*/ switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, evaluationHelper, slotStack); break; case Node.TEXT_NODE: char[] text = node.getText().toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA(); break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() ); this.namespaces.put(declared.getPrefix(), declared.getURI()); //if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); //} //else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); //} break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: //System.err.println( "WARNING: Node type not supported: " + node.getNodeTypeName() ); } } }
From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTDocumentFactory.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) static private void mapContent(Element element, ZPTElement zptElement, ZPTDocument zptDocument, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator<Node> i = element.nodeIterator(); i.hasNext();) { Node node = i.next();/* www. j ava 2 s. c o m*/ switch (node.getNodeType()) { case Node.ELEMENT_NODE: zptElement.addContent(getNewZPTElement((Element) node, zptDocument, slotStack)); break; case Node.TEXT_NODE: zptElement.addContent(new TextNode(node.getText())); break; case Node.CDATA_SECTION_NODE: zptElement.addContent(new CDATANode(node.getText())); break; case Node.NAMESPACE_NODE: // Already handled /* Namespace declared = (Namespace)node; if (zptDocument.isNamespaceToDeclare(declared)){ zptDocument.addNamespace(declared); } else { zptElement.addNamespaceStaticAttribute(declared); } break;*/ case Node.ATTRIBUTE_NODE: // Already handled case Node.COMMENT_NODE: // Remove all comments case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: // Nothing to do } } }
From source file:treesim.TreeSim.java
private static void preParentOrderFirstDOM(Node n) { if (n != null) { if (n.getParent() == null) { System.out.println("ROOT -- \"" + n.getName() + "\""); elementNodes.add(n.getName()); } else {/* w w w . j av a2 s .c om*/ System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\""); elementNodes.add(n.getName()); } for (Object a : ((Element) n).attributes()) { System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + " " + ((Attribute) a).getValue() + "\""); attributeParentNodes.add(n.getName()); attributeNodes.add(((Attribute) a).getName()); } if (!n.getText().trim().equals("")) { System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\""); textNodeConnections.add(n.getName()); } for (Object o : n.selectNodes("child::*")) { if (n.getNodeType() == Node.ELEMENT_NODE) { preParentOrderFirstDOM((Node) o); } } } }
From source file:treesim.TreeSim.java
private static void preParentOrderSecondDOM(Node n) { if (n != null) { if (n.getParent() == null) { System.out.println("ROOT -- \"" + n.getName() + "\""); elementNodes2.add(n.getName()); } else {/*from w w w .j a v a 2 s . c o m*/ System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\""); elementNodes2.add(n.getName()); } for (Object a : ((Element) n).attributes()) { System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + " " + ((Attribute) a).getValue() + "\""); attributeParentNodes2.add(n.getName()); attributeNodes2.add(((Attribute) a).getName()); } if (!n.getText().trim().equals("")) { System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\""); textNodeConnections2.add(n.getName()); } for (Object o : n.selectNodes("child::*")) { if (n.getNodeType() == Node.ELEMENT_NODE) { preParentOrderSecondDOM((Node) o); } } } }