Description
Generates a String that is populated with the textual representation of the XML DOM of the given Document.
License
Open Source License
Parameter
Parameter | Description |
---|
document | The XML Document used to generate the String. |
Exception
Parameter | Description |
---|
IOException | If the encoding fails as a result of an underlyingerror processing the XML. |
Return
A potentially very large String containing the entire DOM as text.
Declaration
public static final String xmlDocumentToString(final Document document) throws IOException
Method Source Code
//package com.java2s;
/*//from w ww . j a va 2s. co m
* The MIT License
*
* Copyright 2013 Emily Mabrey <emilymabrey93@gmail.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import java.io.IOException;
import org.w3c.dom.Document;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
public class Main {
/**
* Generates a String that is populated with the textual representation of
* the XML DOM of the given Document.
*
* @param document The XML Document used to generate the String.
* @return A potentially very large String containing the entire DOM as
* text.
* @throws IOException If the encoding fails as a result of an underlying
* error processing the XML.
*/
public static final String xmlDocumentToString(final Document document) throws IOException {
final DOMImplementationLS domImplementation = (DOMImplementationLS) document.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
return lsSerializer.writeToString(document);
}
}
Related
- xmlDocumentDecode(final String xmlURI)
- xmlDocumentToString(Document doc)
- xmlDocumentToString(Document doc)
- xmlDocumentToString(Document doc)
- xmlDocumentToString(Document document)
- xmlDocumentToString(Node d)
- xmlDOMDocumentToString(Document doc)
- XMLDOMtoString(Document document)
- xmlToFile(Document doc, String fileNameToWrite)