Changeset 5:c8c917786698 in rrlib_xml-java


Ignore:
Timestamp:
04.04.2014 18:43:02 (7 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Children:
6:d881b37d6f77, 8:286f0d108e02
Phase:
public
Message:

Added function to XML document to write it to stream (instead of file)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • XMLDocument.java

    r0 r5  
    174174     * 
    175175     * This method creates or truncates a file with the given name and writes 
    176      * the documents XML representation into it. 
     176     * the document's XML representation into it. 
    177177     * 
    178178     * @param fileName     The name of the file to use 
     
    189189     * 
    190190     * This method creates or truncates a file with the given name and writes 
    191      * the documents XML representation into it. 
     191     * the document's XML representation into it. 
    192192     * 
    193193     * @param fileName     The name of the file to use 
     
    200200     * Write the XML document to a stream 
    201201     * 
     202     * This method writes the document's XML representation to the specified stream 
     203     * 
     204     * @param stream       The stream to write to 
     205     * @param format       Format output? 
     206     */ 
     207    public void writeToStream(StreamResult stream, boolean format) throws Exception { 
     208        writeToStream(stream, format, new DOMSource(document)); 
     209    } 
     210 
     211    /** 
     212     * Write the XML document to a stream 
     213     * 
    202214     * @param result   StreamResult 
    203215     * @param format   Format output? 
    204216     */ 
    205     public static void writeToStream(StreamResult result, boolean format, DOMSource source) throws Exception { 
     217    static void writeToStream(StreamResult result, boolean format, DOMSource source) throws Exception { 
    206218        TransformerFactory factory = TransformerFactory.newInstance(); 
    207219        factory.setAttribute("indent-number", 2); 
     
    209221        if (format) { 
    210222            transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
     223            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); 
    211224        } 
    212225        transformer.transform(source, result); 
  • XMLNode.java

    r4 r5  
    213213        } 
    214214        removeTextContent(); 
    215         node.appendChild(doc.createTextNode(content)); 
     215        if (content != null) { 
     216            node.appendChild(doc.createTextNode(content)); 
     217        } 
    216218    } 
    217219 
Note: See TracChangeset for help on using the changeset viewer.