Page MenuHomec4science

XMLParser.java
No OneTemporary

File Metadata

Created
Sun, Jan 5, 03:30

XMLParser.java

package io.serializer.xml;
import io.serializer.Parser;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.xml.sax.InputSource;
public class XMLParser extends Parser {
private static final Logger LOGGER = Logger.getLogger(XMLParser.class.getName());
private SAXBuilder builder;
private XMLOutputter xmlOutput;
protected static final String SEP_INT = ",";
protected static final String SEP_EXT = ";";
public XMLParser() {
builder = new SAXBuilder();
xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getCompactFormat());
// xmlOutput.setFormat(Format.getPrettyFormat());
}
protected Document stringToDocument(String src) throws JDOMException {
InputSource inputSrc = new InputSource(new StringReader(src));
try {
return builder.build(inputSrc);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
return null;
}
protected String documentToString(Document doc) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlOutput.output(doc, baos);
String res = baos.toString();
return res;
}
}

Event Timeline