本文整理汇总了Java中org.jdom.output.XMLOutputter.setFormat方法的典型用法代码示例。如果您正苦于以下问题:Java XMLOutputter.setFormat方法的具体用法?Java XMLOutputter.setFormat怎么用?Java XMLOutputter.setFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.output.XMLOutputter
的用法示例。
在下文中一共展示了XMLOutputter.setFormat方法的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: 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);
}
}
示例3: getSortedXml
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Returns the sorted xml as an OutputStream.
*
* @return the sorted xml
*/
public String getSortedXml(Document newDocument) {
try (ByteArrayOutputStream sortedXml = new ByteArrayOutputStream()) {
BufferedLineSeparatorOutputStream bufferedLineOutputStream =
new BufferedLineSeparatorOutputStream(lineSeparatorUtil.toString(), sortedXml);
XMLOutputter xmlOutputter = new PatchedXMLOutputter(bufferedLineOutputStream, indentBlankLines);
xmlOutputter.setFormat(createPrettyFormat());
xmlOutputter.output(newDocument, bufferedLineOutputStream);
IOUtils.closeQuietly(bufferedLineOutputStream);
return sortedXml.toString(encoding);
} catch (IOException ioex) {
throw new FailureException("Could not format pom files content", ioex);
}
}
示例4: writeXMLDocument
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public static boolean writeXMLDocument(Document doc, String fName) throws FileNotFoundException {
// Assert.assertNotNull(doc);
if (doc == null)
_log.error("null document");
else {
final long start = System.currentTimeMillis();
FileOutputStream fos = new FileOutputStream(fName);
try {
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
outputter.output(doc, fos);
return true;
} catch (IOException ioe) {
_log.error(ioe);
}
_log.trace("Document written to " + fName + " in: " + TimeUtility.msToHumanReadableDelta(start));
}
return false;
}
示例5: write
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
static void write(File file) throws FileNotFoundException, IOException{
Document document = new Document();
Element root = new Element("document");
root.setAttribute("version", Main.VERSION_ID);
for(Blueprint bp : Main.blueprints){
Element blueprint = writeGraphEditor(bp);
for(VFunction f : bp.getFunctions()){
blueprint.addContent(writeGraphEditor(f.getEditor()));
}
root.addContent(blueprint);
}
document.setRootElement(root);
XMLOutputter output = new XMLOutputter();
Format format = Format.getPrettyFormat();//getRawFormat();
format.setOmitDeclaration(true);
format.setOmitEncoding(true);
format.setTextMode(TextMode.PRESERVE);
output.setFormat(format);
output.output(document, new FileOutputStream(file));
}
示例6: testInsertAtPreferredLocation
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public void testInsertAtPreferredLocation() throws Exception {
NetbeansBuildActionJDOMWriter writer = new NetbeansBuildActionJDOMWriter();
XMLOutputter xmlout = new XMLOutputter();
xmlout.setFormat(Format.getRawFormat().setLineSeparator("\n"));
Element p = new Element("p");
NetbeansBuildActionJDOMWriter.Counter c = writer.new Counter(1);
writer.insertAtPreferredLocation(p, new Element("one"), c);
assertEquals("<p>\n <one />\n</p>", xmlout.outputString(p));
c.increaseCount();
writer.insertAtPreferredLocation(p, new Element("two"), c);
assertEquals("<p>\n <one />\n <two />\n</p>", xmlout.outputString(p));
c = writer.new Counter(1);
writer.insertAtPreferredLocation(p, new Element("zero"), c);
assertEquals("<p>\n <zero />\n <one />\n <two />\n</p>", xmlout.outputString(p));
c.increaseCount();
writer.insertAtPreferredLocation(p, new Element("hemi"), c);
assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <two />\n</p>", xmlout.outputString(p));
c.increaseCount();
c.increaseCount();
writer.insertAtPreferredLocation(p, new Element("sesqui"), c);
assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n</p>", xmlout.outputString(p));
c.increaseCount();
c.increaseCount();
writer.insertAtPreferredLocation(p, new Element("ultimate"), c);
assertEquals("<p>\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n <ultimate />\n</p>", xmlout.outputString(p));
c = writer.new Counter(1);
writer.insertAtPreferredLocation(p, new Element("initial"), c);
assertEquals("<p>\n <initial />\n <zero />\n <hemi />\n <one />\n <sesqui />\n <two />\n <ultimate />\n</p>", xmlout.outputString(p));
// XXX indentation still not right; better to black-box test write(ActionToGoalMapping...)
}
示例7: 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 );
}
示例8: 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());
}
}
示例9: export
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public String export (EctMeasurementTypesBean mtb){
Element measurement = createXMLMeasurement(mtb.getType(),mtb.getTypeDesc(),mtb.getTypeDisplayName(),mtb.getMeasuringInstrc());
EctValidationsBeanHandler valBeanHandler = new EctValidationsBeanHandler();
EctValidationsBean v = valBeanHandler.getValidation(mtb.getValidationName());//(EctValidationsBean) validationRules.get(i);
measurement.addContent(createXMLValidation(v.getName(),v.getMaxValue(),v.getMinValue(),v.getIsDate(),v.getIsNumeric(),v.getRegularExp(),v.getMaxLength(),v.getMinLength()));
XMLOutputter outp = new XMLOutputter();
outp.setFormat(Format.getPrettyFormat());
return outp.outputString(measurement);
}
示例10: getRuleBase
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public RuleBase getRuleBase(String rulesetName, List<Element> elementRules) throws Exception {
long timer = System.currentTimeMillis();
try {
Element va = new Element("rule-set");
addAttributeifValueNotNull(va, "name", rulesetName);
va.setNamespace(namespace);
va.addNamespaceDeclaration(javaNamespace);
va.addNamespaceDeclaration(xsNs);
va.setAttribute("schemaLocation", "http://drools.org/rules rules.xsd http://drools.org/semantics/java java.xsd", xsNs);
for (Element ele : elementRules) {
va.addContent(ele);
}
XMLOutputter outp = new XMLOutputter();
outp.setFormat(Format.getPrettyFormat());
String ooo = outp.outputString(va);
log.debug(ooo);
RuleBase ruleBase=RuleBaseFactory.getRuleBase("RuleBaseCreator:"+ooo);
if (ruleBase!=null) return(ruleBase);
ruleBase = RuleBaseLoader.loadFromInputStream(new ByteArrayInputStream(ooo.getBytes()));
RuleBaseFactory.putRuleBase("RuleBaseCreator:"+ooo, ruleBase);
return ruleBase;
} finally {
log.debug("generateRuleBase TimeMs : " + (System.currentTimeMillis() - timer));
}
}
示例11: writeToXmlFile
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Write the new data to the xml file
*/
private void writeToXmlFile() throws Exception {
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(configurationXmlDocument, new OutputStreamWriter(
new FileOutputStream(new File(configurationFilePath)), "UTF-8"));
}
示例12: writeAlertsToFile
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
private static void writeAlertsToFile(File outputFile, Document doc) {
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getPrettyFormat());
try {
xmlOutput.output(doc, new FileWriter(outputFile));
System.out.println("alert xml report saved to: "+outputFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: flush
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
public void flush() throws IOException
{
XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat());
Format f = xmlcode.getFormat();
f.setEncoding("ISO-8859-1");
f.setTextMode(Format.TextMode.PRESERVE);
f.setLineSeparator(System.getProperty("line.separator"));
xmlcode.setFormat(f);
//Open a filewriter
PrintWriter writer = new PrintWriter(out);
xmlcode.output(doc, writer);
out.flush();
}
示例14: createOutputter
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
@NotNull
public static XMLOutputter createOutputter(String lineSeparator) {
XMLOutputter xmlOutputter = new MyXMLOutputter();
Format format = Format.getCompactFormat().
setIndent(" ").
setTextMode(Format.TextMode.TRIM).
setEncoding(CharsetToolkit.UTF8).
setOmitEncoding(false).
setOmitDeclaration(false).
setLineSeparator(lineSeparator);
xmlOutputter.setFormat(format);
return xmlOutputter;
}
示例15: printElement
import org.jdom.output.XMLOutputter; //导入方法依赖的package包/类
private String printElement(Element root) throws IOException {
XMLOutputter xmlOutputter = JDOMUtil.createOutputter("\n");
final Format format = xmlOutputter.getFormat().setOmitDeclaration(true).setOmitEncoding(true).setExpandEmptyElements(true);
xmlOutputter.setFormat(format);
CharArrayWriter writer = new CharArrayWriter();
xmlOutputter.output(root, writer);
String res = new String(writer.toCharArray());
return res;
}