/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
protected void writeContent(Branch branch, NamespaceStack namespaceStack) throws SAXException { for (Iterator<Node> iter = branch.nodeIterator(); iter.hasNext();) { Node node = iter.next(); if (node instanceof Element) { write((Element) node, namespaceStack); } else if (node instanceof CharacterData) { if (node instanceof Text) { Text text = (Text) node; write(text.getText()); } else if (node instanceof CDATA) { write((CDATA) node); } else if (node instanceof Comment) { write((Comment) node); } else { throw new SAXException("Invalid Node in DOM4J content: " + node + " of type: " + node.getClass()); } } else if (node instanceof Entity) { write((Entity) node); } else if (node instanceof ProcessingInstruction) { write((ProcessingInstruction) node); } else if (node instanceof Namespace) { write((Namespace) node); } else { throw new SAXException("Invalid Node in DOM4J content: " + node); } } }
/** * Generates SAX events for the given CDATA * * @param cdata * is the CDATA to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(CDATA cdata) throws SAXException { String text = cdata.getText(); if (lexicalHandler != null) { lexicalHandler.startCDATA(); write(text); lexicalHandler.endCDATA(); } else { write(text); } }
/** * Generates SAX events for the given Entity * * @param entity * is the Entity to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Entity entity) throws SAXException { String text = entity.getText(); if (lexicalHandler != null) { String name = entity.getName(); lexicalHandler.startEntity(name); write(text); lexicalHandler.endEntity(name); } else { write(text); } }
/** * Parses an XML document. This method can only accept DocumentInputSource * inputs otherwise a {@link SAXNotSupportedException}exception is thrown. * * @param input * DOCUMENT ME! * * @throws SAXException * DOCUMENT ME! * @throws SAXNotSupportedException * if the input source is not wrapping a dom4j document */ public void parse(InputSource input) throws SAXException { if (input instanceof DocumentInputSource) { DocumentInputSource documentInput = (DocumentInputSource) input; Document document = documentInput.getDocument(); write(document); } else { throw new SAXNotSupportedException( "This XMLReader can only accept " + "<dom4j> InputSource objects"); } }
/** 将W3C element转换成SAX事件。 */ public static void convertElement(Element element, ContentHandler contentHandler) throws SAXException { SAXWriter writer = new SAXWriter(contentHandler); if (contentHandler instanceof ErrorHandler) { writer.setErrorHandler((ErrorHandler) contentHandler); } if (contentHandler instanceof LexicalHandler) { writer.setLexicalHandler((LexicalHandler) contentHandler); } writer.write(convertElement(element)); }
/** 将W3C element转换成SAX事件。 */ public static void convertElement(Element element, ContentHandler contentHandler) throws SAXException { SAXWriter writer = new SAXWriter(contentHandler); if (contentHandler instanceof ErrorHandler) { writer.setErrorHandler((ErrorHandler) contentHandler); } if (contentHandler instanceof LexicalHandler) { writer.setLexicalHandler((LexicalHandler) contentHandler); } writer.write(convertElement(element)); }
/** 将W3C element转换成SAX事件。 */ public static void convertElement(Element element, ContentHandler contentHandler) throws SAXException { SAXWriter writer = new SAXWriter(contentHandler); if (contentHandler instanceof ErrorHandler) { writer.setErrorHandler((ErrorHandler) contentHandler); } if (contentHandler instanceof LexicalHandler) { writer.setLexicalHandler((LexicalHandler) contentHandler); } writer.write(convertElement(element)); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Generates SAX events for the given Element and all its content * * @param element * is the Element to parse * * @throws SAXException * if there is a SAX error processing the events */ public void write(Element element) throws SAXException { write(element, new NamespaceStack()); }
/** * Writes the output element to the XML output writer and detaches it * from it's parent element.<p> * * @param parent the parent element * @param output the output element * * @throws SAXException if something goes wrong processing the manifest.xml */ protected void digestElement(Element parent, Element output) throws SAXException { m_saxWriter.write(output); parent.remove(output); }
/** 将W3C element转换成SAX事件。 */ public static void convertElement(Element element, ContentHandler contentHandler) throws SAXException { SAXWriter writer = new SAXWriter(contentHandler); if (contentHandler instanceof ErrorHandler) { writer.setErrorHandler((ErrorHandler) contentHandler); } if (contentHandler instanceof LexicalHandler) { writer.setLexicalHandler((LexicalHandler) contentHandler); } writer.write(convertElement(element)); }
protected Document roundTripSAX(Document document) throws Exception { // now lets write it back as SAX events to // a SAX ContentHandler which should build up a new document SAXContentHandler contentHandler = new SAXContentHandler(); SAXWriter saxWriter = new SAXWriter(contentHandler, contentHandler, contentHandler); saxWriter.write(document); Document newDocument = contentHandler.getDocument(); // lets ensure names are same newDocument.setName(document.getName()); assertDocumentsEqual(document, newDocument); return newDocument; }