Java XML Node Save writeXMLwithXALAN(final Writer writer, final Node node, final String xmlEncoding)

Here you can find the source of writeXMLwithXALAN(final Writer writer, final Node node, final String xmlEncoding)

Description

write XM Lwith XALAN

License

Open Source License

Declaration

private static void writeXMLwithXALAN(final Writer writer, final Node node, final String xmlEncoding) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2011 [Gobierno de Espana]
 * This file is part of "Cliente @Firma".
 * "Cliente @Firma" is free software; you can redistribute it and/or modify it under the terms of:
 *   - the GNU General Public License as published by the Free Software Foundation;
 *     either version 2 of the License, or (at your option) any later version.
 *   - or The European Software License; either version 1.1 or (at your option) any later version.
 * Date: 11/01/11/*from  w w w . j a v a  2 s  . c  o m*/
 * You may contact the copyright holder at: soporte.afirma5@mpt.es
 */

import java.io.Writer;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer;

public class Main {
    private static void writeXMLwithXALAN(final Writer writer, final Node node, final String xmlEncoding) {

        DOMImplementationLS domImplLS;
        final Document doc = node.getOwnerDocument();
        if (doc.getFeature("Core", "3.0") != null && doc.getFeature("LS", "3.0") != null) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            domImplLS = (DOMImplementationLS) doc.getImplementation().getFeature("LS", "3.0"); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            throw new RuntimeException("La implementacion DOM cargada no permite la serializacion"); //$NON-NLS-1$
        }

        final LSOutput output = domImplLS.createLSOutput();
        output.setCharacterStream(writer);
        if (xmlEncoding != null) {
            output.setEncoding(xmlEncoding);
        }

        final LSSerializer serializer = domImplLS.createLSSerializer();
        serializer.getDomConfig().setParameter("namespaces", Boolean.FALSE); //$NON-NLS-1$

        serializer.write(node, output);
    }
}

Related

  1. writeToStream(OutputStream os, Node node)
  2. writeToString(Node node)
  3. writeToString(Node node)
  4. writeXml(final Node node)
  5. writeXMLwalkTree(Node node, int indent, PrintWriter out)
  6. writeXMLwithXALAN(final Writer writer, final Node node, final String xmlEncoding)
  7. xmlSelectNodes0(List list, Node node, String path[], int n)
  8. xmltostring(String indent, Node node)