switch (n.getNodeType()) { case Node.ELEMENT_NODE: writeElement((Element) n); writeText((Text) n); writeAttribute((Attribute) n); writeNamespace((Namespace) n); writeComment((Comment) n); writeCDATA((CDATA) n); writeProcessingInstruction((org.dom4j.ProcessingInstruction) n); writeEntity((Entity) n); writeDocument((Document) n); writeDocumentType((DocumentType) n);
/** * Writes each child node within the provided {@link Branch}instance. This * method simply iterates through the {@link Branch}'s nodes and calls * {@link #writeNode(Node)}. * * @param branch * The node whose children will be written to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeChildNodes(Branch branch) throws XMLStreamException { for (int i = 0, s = branch.nodeCount(); i < s; i++) { Node n = branch.node(i); writeNode(n); } }
/** * Writes a DOM4J {@link Attribute}to the stream. * * @param attr * The {@link Attribute}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeAttribute(Attribute attr) throws XMLStreamException { consumer.add(createAttribute(attr)); }
/** * Writes a DOM4J {@link Element}node and its children to the stream. * * @param elem * The {@link Element}node to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeElement(Element elem) throws XMLStreamException { consumer.add(createStartElement(elem)); writeChildNodes(elem); consumer.add(createEndElement(elem)); }
/** * Writes a DOM4J {@link Document}node, and all its contents, to the * stream. * * @param doc * The {@link Document}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeDocument(Document doc) throws XMLStreamException { consumer.add(createStartDocument(doc)); writeChildNodes(doc); consumer.add(createEndDocument(doc)); }
/** * Writes a DOM4J {@link Text}to the stream. * * @param text * The {@link Text}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeText(Text text) throws XMLStreamException { consumer.add(createCharacters(text)); }
/** * Writes a DOM4J {@link Entity}to the stream. * * @param entity * The {@link Entity}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeEntity(Entity entity) throws XMLStreamException { consumer.add(createEntityReference(entity)); }
/** * Writes a DOM4J {@link Comment}to the stream. * * @param comment * The {@link Comment}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeComment(Comment comment) throws XMLStreamException { consumer.add(createComment(comment)); }
/** * Writes a DOM4J {@link Namespace}to the stream. * * @param ns * The {@link Namespace}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeNamespace(Namespace ns) throws XMLStreamException { consumer.add(createNamespace(ns)); }
/** * Writes a DOM4J {@link DocumentType}to the stream. * * @param docType * The {@link DocumentType}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeDocumentType(DocumentType docType) throws XMLStreamException { consumer.add(createDTD(docType)); }
public String toXml1(XmlObject xmlObject) throws ConversionException { //TODO for some reason, this does not marshall at all, and also, will it be faster than dom4j XMLWriter? Dom4jXmlObject dom4jXmlObject = (Dom4jXmlObject) xmlObject; StringBuilderWriter stringWriter = StringBuilderWriter.Cached.cached(); try { STAXEventWriter xmlWriter = new STAXEventWriter(stringWriter); xmlWriter.writeNode(dom4jXmlObject.getNode()); } catch (XMLStreamException e) { throw new ConversionException("Failed to write xml", e); } return stringWriter.toString(); } }
STAXEventWriter xmlWriter = new STAXEventWriter(writer); xmlWriter.writeDocument(doc);
/** * Writes a DOM4J {@link Element}node and its children to the stream. * * @param elem * The {@link Element}node to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeElement(Element elem) throws XMLStreamException { consumer.add(createStartElement(elem)); writeChildNodes(elem); consumer.add(createEndElement(elem)); }
/** * Writes a DOM4J {@link Document}node, and all its contents, to the * stream. * * @param doc * The {@link Document}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeDocument(Document doc) throws XMLStreamException { consumer.add(createStartDocument(doc)); writeChildNodes(doc); consumer.add(createEndDocument(doc)); }
/** * Writes a DOM4J {@link CDATA}to the event stream. * * @param cdata * The {@link CDATA}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeCDATA(CDATA cdata) throws XMLStreamException { consumer.add(createCharacters(cdata)); }
/** * Writes a DOM4J {@link Entity}to the stream. * * @param entity * The {@link Entity}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeEntity(Entity entity) throws XMLStreamException { consumer.add(createEntityReference(entity)); }
/** * Writes a DOM4J {@link Comment}to the stream. * * @param comment * The {@link Comment}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeComment(Comment comment) throws XMLStreamException { consumer.add(createComment(comment)); }
/** * Writes a DOM4J {@link Namespace}to the stream. * * @param ns * The {@link Namespace}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeNamespace(Namespace ns) throws XMLStreamException { consumer.add(createNamespace(ns)); }
/** * Writes a DOM4J {@link DocumentType}to the stream. * * @param docType * The {@link DocumentType}to write to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeDocumentType(DocumentType docType) throws XMLStreamException { consumer.add(createDTD(docType)); }
switch (n.getNodeType()) { case Node.ELEMENT_NODE: writeElement((Element) n); writeText((Text) n); writeAttribute((Attribute) n); writeNamespace((Namespace) n); writeComment((Comment) n); writeCDATA((CDATA) n); writeProcessingInstruction((org.dom4j.ProcessingInstruction) n); writeEntity((Entity) n); writeDocument((Document) n); writeDocumentType((DocumentType) n);