private static XMLSerializer getXMLSerializer(final OutputStream os, final String[] cdataElements) throws InstantiationException, IllegalAccessException, ClassNotFoundException { // configure an OutputFormat to handle CDATA final OutputFormat of = new OutputFormat(); // specify which of your elements you want to be handled as CDATA. // The use of the '^' between the namespaceURI and the localname // seems to be an implementation detail of the xerces code. // When processing xml that doesn't use namespaces, simply omit the // namespace prefix as shown in the third CDataElement below. of.setCDataElements(cdataElements); // set any other options you'd like of.setPreserveSpace(true); of.setIndenting(true); // create the serializer final XMLSerializer serializer = new XMLSerializer(of); serializer.setOutputByteStream(os); return serializer; }
DataOutputStream out = new DataOutputStream(s.getOutputStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLSerializer serializer = new XMLSerializer(); serializer.setOutputByteStream(baos); tosend = WUTPClientWriter.createMessage100(projectid, cpuclock, cpunumber); serializer.serialize(tosend); out.writeInt(baos.size()); out.write(baos.toByteArray()); out.flush();
@SuppressWarnings("deprecation") public static String serializeDoctoString(Document doc) throws IOException { org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); serializer.setOutputByteStream(bout); serializer.serialize(doc); return bout.toString(); }
/** * Constructs a new serializer that writes to the specified output * stream using the specified output format. If <tt>format</tt> * is null, will use a default output format. * * @param output The output stream to use * @param format The output format to use, null for the default */ public XMLSerializer( OutputStream output, OutputFormat format ) { super( format != null ? format : new OutputFormat( Method.XML, null, false ) ); _format.setMethod( Method.XML ); setOutputByteStream( output ); }
/** * @param doc DOM Document * @throws IOException */ @SuppressWarnings("deprecation") public static void serializeDoc(Document doc) throws IOException { org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(); serializer.setOutputByteStream(System.out); serializer.serialize(doc); }
public void serialize(OutputStream os, Node node, Format format) throws XMLException { try { XMLSerializer ser = createXMLSerializer(node,format); ser.setOutputByteStream(os); serialize(ser,node); } catch(Exception e) { throw new XMLException(e,"Error while converting XML document to string"); // $NLS-AbstractXercesDriver.ErrorwhileconvertingXMLdocumentto-1$ } }
private static XMLSerializer getXMLSerializer( OutputStream os ) throws InstantiationException, IllegalAccessException, ClassNotFoundException { OutputFormat of = new OutputFormat(); of.setCDataElements( new String[] { "ns1^commentText", "ns2^commentText", "^commentText" } ); XMLSerializer serializer = new XMLSerializer( of ); serializer.setOutputByteStream( os ); return serializer; }
OutputFormat of = new OutputFormat("XML","UTF-8",true); XMLSerializer serializer = new XMLSerializer(); serializer.setOutputFormat(of); serializer.setOutputByteStream(new FileOutputStream(PATH)); serializer.serialize(doc);
public static ContentHandler getXercesSerializer(OutputStream os) { XMLSerializer serializer = new XMLSerializer(); OutputFormat format = new OutputFormat(); format.setPreserveSpace(true); format.setOmitDocumentType(true); serializer.setOutputFormat(format); serializer.setOutputByteStream(os); return serializer; } }
public static void writeXml(Element element, OutputStream os) throws IOException { OutputFormat format = new OutputFormat("XML", "UTF-8", false); format.setOmitComments(false); format.setLineWidth(0); XMLSerializer serializer = new XMLSerializer(format); serializer.setOutputByteStream(os); serializer.serialize(element); }
private static XMLSerializer getXMLSerializer( OutputStream os, String[] cdataElements ) throws InstantiationException, IllegalAccessException, ClassNotFoundException { // configure an OutputFormat to handle CDATA OutputFormat of = new OutputFormat(); // specify which of your elements you want to be handled as CDATA. // The use of the '^' between the namespaceURI and the localname // seems to be an implementation detail of the xerces code. // When processing xml that doesn't use namespaces, simply omit the // namespace prefix as shown in the third CDataElement below. of.setCDataElements( cdataElements ); // set any other options you'd like of.setPreserveSpace(true); of.setIndenting(true); // create the serializer XMLSerializer serializer = new XMLSerializer(of); serializer.setOutputByteStream( os ); return serializer; }
case xml: XMLSerializer xmlSerializer = new XMLSerializer(); xmlSerializer.setOutputByteStream(out); OutputFormat format = new OutputFormat(); format.setIndenting(true);
prepareForSerialization(ser, node); ser._format.setEncoding(encoding); ser.setOutputByteStream(XMLEntityManager.createOutputStream(URI));
ser.setOutputByteStream(XMLEntityManager.createOutputStream(uri)); ser.setOutputByteStream(outputStream);