java.lang.Object
io.jenetics.xml.stream.XML
This class contains helper methods for creating
Create a new XML stream reader:
Create a new XML stream reader with pretty-print-indentation:
XMLStreamReader and
XMLStreamWriter objects.
Creating a new XML stream reader:
try (AutoCloseableXMLStreamReader xml = XML.reader(in)) {
// Move XML stream to first element.
xml.next();
return reader.read(xml);
}
try (AutoCloseableXMLStreamWriter xml = XML.writer(out)) {
writer.write(value, xml);
}
final String indent = " ";
try (AutoCloseableXMLStreamWriter xml = XML.writer(out, indent)) {
writer.write(value, xml);
}
- Since:
- 3.9
- Version:
- 3.9
-
Method Summary
Modifier and TypeMethodDescriptionstatic AutoCloseableXMLStreamReaderreader(InputStream input) Create a new XML stream reader from the giveninputstream.static AutoCloseableXMLStreamWriterwriter(OutputStream output) Create a newXMLStreamWriterfrom the given output stream.static AutoCloseableXMLStreamWriterwriter(OutputStream output, String indent) Create a newXMLStreamWriterfrom the given output stream.
-
Method Details
-
reader
Create a new XML stream reader from the giveninputstream. The caller is responsible for closing the returnedXMLStreamReader.try (AutoCloseableXMLStreamReader xml = XML.reader(in)) { // Move XML stream to first element. xml.next(); return reader.read(xml); }- Parameters:
input- the input stream- Returns:
- a new
CloseableXML stream reader - Throws:
XMLStreamException- if the creation of the XML stream reader failsNullPointerException- if the giveninputstream isnull
-
writer
public static AutoCloseableXMLStreamWriter writer(OutputStream output, String indent) throws XMLStreamException Create a newXMLStreamWriterfrom the given output stream. The caller is responsible for closing the returnedXMLStreamWriter.try (AutoCloseableXMLStreamWriter xml = XML.writer(out, " ")) { writer.write(value, xml); }- Parameters:
output- the underlying output streamindent- the element indent used for the XML output- Returns:
- a new
XMLStreamWriterinstance - Throws:
XMLStreamException- if an error occurs while creating the XML stream writerNullPointerException- if the givenoutputstream isnull
-
writer
Create a newXMLStreamWriterfrom the given output stream. The caller is responsible for closing the returnedXMLStreamWriter.try (AutoCloseableXMLStreamWriter xml = XML.writer(out)) { writer.write(value, xml); }- Parameters:
output- the underlying output stream- Returns:
- a new
XMLStreamWriterinstance - Throws:
XMLStreamException- if an error occurs while creating the XML stream writerNullPointerException- if the givenoutputstream isnull
-