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:architecture.common.xml.XmlWriter.java
License:Apache License
@Override public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { try {/*from w ww .j ava2s . c o m*/ charactersAdded = false; writePrintln(); indent(); writer.write("<"); writer.write(qName); writeNamespaces(); writeAttributes(attributes); writer.write(">"); ++indentLevel; lastOutputNodeType = Node.ELEMENT_NODE; super.startElement(namespaceURI, localName, qName, attributes); } catch (IOException e) { handleException(e); } }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
@Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try {//from w w w . java2 s . co m charactersAdded = false; --indentLevel; if (lastOutputNodeType == Node.ELEMENT_NODE) { writePrintln(); indent(); } // XXXX: need to determine this using a stack and checking for // content / children boolean hadContent = true; if (hadContent) { writeClose(qName); } else { writeEmptyElementClose(qName); } lastOutputNodeType = Node.ELEMENT_NODE; super.endElement(namespaceURI, localName, qName); } catch (IOException e) { handleException(e); } }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeElement(Element element) throws IOException { int size = element.nodeCount(); String qualifiedName = element.getQualifiedName(); writePrintln();/*from w w w . ja va 2 s. c o m*/ indent(); writer.write("<"); writer.write(qualifiedName); int previouslyDeclaredNamespaces = namespaceStack.size(); Namespace ns = element.getNamespace(); if (isNamespaceDeclaration(ns)) { namespaceStack.push(ns); writeNamespace(ns); } // Print out additional namespace declarations boolean textOnly = true; for (int i = 0; i < size; i++) { Node node = element.node(i); if (node instanceof Namespace) { Namespace additional = (Namespace) node; if (isNamespaceDeclaration(additional)) { namespaceStack.push(additional); writeNamespace(additional); } } else if (node instanceof Element) { textOnly = false; } else if (node instanceof Comment) { textOnly = false; } } writeAttributes(element); lastOutputNodeType = Node.ELEMENT_NODE; if (size <= 0) { writeEmptyElementClose(qualifiedName); } else { writer.write(">"); if (textOnly) { // we have at least one text node so lets assume // that its non-empty writeElementContent(element); } else { // we know it's not null or empty from above ++indentLevel; writeElementContent(element); --indentLevel; writePrintln(); indent(); } writer.write("</"); writer.write(qualifiedName); writer.write(">"); } // remove declared namespaceStack from stack while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop(); } lastOutputNodeType = Node.ELEMENT_NODE; }
From source file:architecture.common.xml.XmlWriter.java
License:Apache License
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeElement((Element) node); break;//from ww w . jav a 2s . c om case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeNodeText(node); // write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes // write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:architecture.ee.util.xml.XmlWriter.java
License:Apache License
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeElement((Element) node); break;/*from www .j a v a 2s . c om*/ case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeNodeText(node); //write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes //write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
From source file:bixo.examples.webmining.AnalyzeHtml.java
License:Apache License
private String getAttributeFromNode(Node node, String attribute) { String attributeValue = null; if (node.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) node; attributeValue = e.attributeValue(attribute); }/*from w ww .ja va 2 s. co m*/ return (attributeValue == null ? "" : attributeValue); }
From source file:com.christophermrossi.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, 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();/*from ww w . j a v a 2s. c om*/ break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() ); 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:com.cladonia.xml.ExchangerXMLWriter.java
License:Open Source License
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { try {//w w w . j a v a 2 s . c om writePrintln(); indent(); writer.write("<"); writer.write(qName); writeNamespaces(); writeAttributes(attributes); writer.write(">"); ++indentLevel; lastOutputNodeType = Node.ELEMENT_NODE; super.startElement(namespaceURI, localName, qName, attributes); } catch (IOException e) { handleException(e); } }
From source file:com.cladonia.xml.ExchangerXMLWriter.java
License:Open Source License
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try {//from w ww .j a v a 2 s . com --indentLevel; if (lastOutputNodeType == Node.ELEMENT_NODE) { writePrintln(); indent(); } // XXXX: need to determine this using a stack and checking for // content / children boolean hadContent = true; if (hadContent) { writeClose(qName); } else { writeEmptyElementClose(qName); } lastOutputNodeType = Node.ELEMENT_NODE; super.endElement(namespaceURI, localName, qName); } catch (IOException e) { handleException(e); } }
From source file:com.cladonia.xml.ExchangerXMLWriter.java
License:Open Source License
protected void writeXElement(XElement element) throws IOException { int size = element.nodeCount(); String qualifiedName = element.getQualifiedName(); writePrintln();/*from ww w.j ava 2 s . c o m*/ indent(); element.setElementStartPosition(((PositionedWriter) writer).getPosition()); // System.out.print( "["+((PositionedWriter)writer).getPosition()+"]"); writer.write("<"); writer.write(qualifiedName); int previouslyDeclaredNamespaces = namespaceStack.size(); Namespace ns = element.getNamespace(); if (isNamespaceDeclaration(ns)) { namespaceStack.push(ns); writeNamespace(ns); } // Print out additional namespace declarations boolean textOnly = true; for (int i = 0; i < size; i++) { Node node = element.node(i); if (node instanceof Namespace) { Namespace additional = (Namespace) node; if (isNamespaceDeclaration(additional)) { namespaceStack.push(additional); writeNamespace(additional); } } else if (node instanceof Element) { textOnly = false; } } writeAttributes(element); lastOutputNodeType = Node.ELEMENT_NODE; if (size <= 0) { writeEmptyElementClose(qualifiedName); } else { writer.write(">"); element.setContentStartPosition(((PositionedWriter) writer).getPosition()); if (textOnly) { // we have at least one text node so lets assume // that its non-empty writeElementContent(element); } else { XElement[] elements = element.getElements(); boolean allNotParsed = true; for (int i = 0; i < elements.length; i++) { if (elements[i].isParsed()) { allNotParsed = false; break; } } // we know it's not null or empty from above ++indentLevel; writeElementContent(element); --indentLevel; // All Children were not parsed so the end-tag has been newly created // ED: This could still be a previous element ending though! if (allNotParsed) { format.setNewlines(true); format.setIndent(indentString); } writePrintln(); indent(); if (allNotParsed) { // reset format.setNewlines(false); format.setIndent(""); } } element.setContentEndPosition(((PositionedWriter) writer).getPosition()); writer.write("</"); writer.write(qualifiedName); writer.write(">"); } element.setElementEndPosition(((PositionedWriter) writer).getPosition()); // System.out.print( "["+((PositionedWriter)writer).getPosition()+"]"); // remove declared namespaceStack from stack while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop(); } lastOutputNodeType = Node.ELEMENT_NODE; }