本文整理汇总了Java中org.jdom.output.XMLOutputter.output方法的典型用法代码示例。如果您正苦于以下问题:Java XMLOutputter.output方法的具体用法?Java XMLOutputter.output怎么用?Java XMLOutputter.output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.output.XMLOutputter
的用法示例。
在下文中一共展示了XMLOutputter.output方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doOutput
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public void doOutput(List<StudentEntity> students){
Element root = new Element("students");
Document document = new Document(root);
Iterator<StudentEntity> iter = students.iterator();
while(iter.hasNext()){
StudentEntity student = iter.next();
Element studentEl = new Element("student");
studentEl.addContent(new Element("studentnumber").setText(student.getStudentNumber()));
studentEl.addContent(new Element("studentname").setText(student.getStudentName()));
studentEl.addContent(new Element("major").setText(student.getMajor()));
studentEl.addContent(new Element("grade").setText(student.getGrade()));
studentEl.addContent(new Element("classname").setText(student.getClassName()));
studentEl.addContent(new Element("gender").setText(student.getGender()));
root.addContent(studentEl);
}
try {
XMLOutputter out = new XMLOutputter();
Format f = Format.getPrettyFormat();
f.setEncoding("UTF-8");
out.setFormat(f);
out.output(document, new FileOutputStream(outputFile));
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: toDom
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Convert the received jdom doc to a Document element.
*
* @param doc the doc
* @return the org.w3c.dom. document
*/
private org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
final DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
dbf.setNamespaceAware(true);
return dbf.newDocumentBuilder().parse(
new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
logger.trace(e.getMessage(), e);
return null;
}
}
示例3: writeToXml
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Writes the JDOM document to the outputstream specified
* @param out the outputstream to which the JDOM document should be writed
* @param validate if true, validate the dom structure before writing. If there is a validation error,
* or the xsd is not in the classpath, an exception will be thrown.
* @throws ConverterException
*/
public void writeToXml(Pathway pwy, OutputStream out, boolean validate) throws ConverterException {
Document doc = createJdom(pwy);
//Validate the JDOM document
if (validate) validateDocument(doc);
// Get the XML code
XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat());
Format f = xmlcode.getFormat();
f.setEncoding("UTF-8");
f.setTextMode(Format.TextMode.PRESERVE);
xmlcode.setFormat(f);
try
{
//Send XML code to the outputstream
xmlcode.output(doc, out);
}
catch (IOException ie)
{
throw new ConverterException(ie);
}
}
示例4: printXML
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public static void printXML(Document doc){
Format format = Format.getPrettyFormat();
format.setIndent("\t");
XMLOutputter op = new XMLOutputter(format);
if(doc == null){
System.err.println("Null document");
}
else{
try {
op.output(doc, System.out);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println();
}
}
示例5: export
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* @param t_objdb
* @param string
* @throws IOException
* @throws SQLException
*/
public void export(DBInterface a_objDB, String a_strFileName) throws IOException, SQLException
{
this.m_objDB = a_objDB;
// Erzeugung eines XML-Dokuments
Document t_objDocument = new Document();
// Erzeugung des Root-XML-Elements
Element t_objRoot = new Element("defaults");
Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
t_objRoot.addNamespaceDeclaration(xsiNS);
this.exportResidues(t_objRoot);
this.exportPersubstitutions(t_objRoot);
this.exportIons(t_objRoot);
this.exportDericatisation(t_objRoot);
this.exportMolecules(t_objRoot);
// Und jetzt haengen wir noch das Root-Element an das Dokument
t_objDocument.setRootElement(t_objRoot);
// Damit das XML-Dokument schoen formattiert wird holen wir uns ein Format
Format t_objFormat = Format.getPrettyFormat();
t_objFormat.setEncoding("iso-8859-1");
// Erzeugung eines XMLOutputters dem wir gleich unser Format mitgeben
XMLOutputter t_objExportXML = new XMLOutputter(t_objFormat);
// Schreiben der XML-Datei in einen String
FileWriter t_objWriter = new FileWriter(a_strFileName);
t_objExportXML.output(t_objDocument, t_objWriter );
}
示例6: toDom
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Convert the received jdom doc to a Document element.
*
* @param doc the doc
* @return the org.w3c.dom. document
*/
private static org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes(Charset.defaultCharset());
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://apache.org/xml/features/validation/schema/normalized-value", false);
dbf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
return dbf.newDocumentBuilder().parse(new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
LOGGER.trace(e.getMessage(), e);
return null;
}
}
示例7: toDom
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
private static org.w3c.dom.Document toDom(final Document doc) {
try {
final XMLOutputter xmlOutputter = new XMLOutputter();
final StringWriter elemStrWriter = new StringWriter();
xmlOutputter.output(doc, elemStrWriter);
final byte[] xmlBytes = elemStrWriter.toString().getBytes();
final DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
dbf.setNamespaceAware(true);
return dbf.newDocumentBuilder().parse(
new ByteArrayInputStream(xmlBytes));
} catch (final Exception e) {
return null;
}
}
示例8: processFullCreoleXmlTree
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
private void processFullCreoleXmlTree(Plugin plugin,
Document jdomDoc, CreoleAnnotationHandler annotationHandler)
throws GateException, IOException, JDOMException {
// now we can process any annotations on the new classes
// and augment the XML definition
annotationHandler.processAnnotations(jdomDoc);
// debugging
if(DEBUG) {
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
xmlOut.output(jdomDoc, System.out);
}
// finally, parse the augmented definition with the normal parser
DefaultHandler handler =
new CreoleXmlHandler(this, plugin);
SAXOutputter outputter =
new SAXOutputter(handler, handler, handler, handler);
outputter.output(jdomDoc);
if(DEBUG) {
Out.prln("done parsing " + plugin);
}
}
示例9: save
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public void save(File sav) {
Document document = new Document();
Element root = new Element("blocks");
document.setRootElement(root);
for (int x = 0; x < BLOCKS_WIDTH; x++) {
for (int y = 0; y < BLOCKS_HEIGHT; y++) {
Element block = new Element("block");
block.setAttribute("x", String.valueOf((int) (blocks[x][y].getX() / BLOCK_SIZE)));
block.setAttribute("y", String.valueOf((int) (blocks[x][y].getY() / BLOCK_SIZE)));
block.setAttribute("type", String.valueOf(blocks[x][y].getType()));
root.addContent(block);
}
}
XMLOutputter output = new XMLOutputter();
try {
output.output(document, new FileOutputStream(sav));
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: write
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Method write
*
* @param project
* @param stream
* @param document
* @deprecated
*/
public void write( Model project, Document document, OutputStream stream )
throws java.io.IOException
{
updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
XMLOutputter outputter = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) );
outputter.setFormat( format );
outputter.output( document, stream );
}
示例11: writeXML
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Write the HMM parameters to a xml file.
*
* @param hmm the markovmodel of which should be written
* @param file the output file
*/
public static void writeXML(HMM hmm, String file)
{
try
{
_LOGGER.info("Writing markovmodel to xml.");
Element hmmxml = new Element("markovmodel");
Document doc = new Document(hmmxml);
doc.setRootElement(hmmxml);
Element meta = new Element("meta");
hmmxml.addContent(meta);
addMeta(hmm, meta);
if (hmm.isTrained())
{
Element ortho = new Element("ortho");
hmmxml.addContent(ortho);
addOrtho(hmm, ortho);
}
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter(file));
}
catch (IOException e)
{
_LOGGER.error("Error when writing xmlFile: " + e.getMessage());
}
}
示例12: outputXML
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public void outputXML(File outputFile, Element element, boolean append) {
try {
FileWriter xmlout = new FileWriter(outputFile, append);
org.jdom.output.Format format = org.jdom.output.Format.getPrettyFormat();
format.setLineSeparator(System.getProperty("line.separator"));
XMLOutputter outputter =
new XMLOutputter(format);
outputter.output(element, xmlout);
xmlout.write("\n");
// Close the FileWriter
xmlout.close();
}
catch (java.io.IOException e) {
System.err.println(e.getMessage());
}
}
示例13: writeConfiguration
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
private static void writeConfiguration(RunConfiguration configuration, File outputFile) {
try (FileOutputStream writer = new FileOutputStream(outputFile, false)) {
XMLOutputter xmlOutputter = new XMLOutputter(Format.getCompactFormat());
xmlOutputter.output(RunConfigurationSerializer.writeToXml(configuration), writer);
} catch (IOException e) {
throw new RuntimeException("Error exporting run configuration to file: " + outputFile);
}
}
示例14: toString
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public String toString(Format format) {
StringWriter xmlout = new StringWriter();
try {
format.setLineSeparator(System.getProperty("line.separator"));
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(this.element, xmlout);
// Close the FileWriter
xmlout.close();
} catch (java.io.IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return xmlout.toString();
}
示例15: output
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Output the JDOM tree to the specified stream as an XML document.
**/
public void output(OutputStream out) throws IOException {
// JDOM can output JDOM trees in a variety of ways (such as converting
// them to DOM trees or SAX event streams). Here we use an "outputter"
// that converts a JDOM tree to an XML document
XMLOutputter outputter = new XMLOutputter(" ", // indentation
true); // use newlines
outputter.output(document, out);
}