當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLOutputter.setFormat方法代碼示例

本文整理匯總了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();  
        }  
}
 
開發者ID:ousheobin,項目名稱:My-Javaweb-Homework,代碼行數:26,代碼來源:XMLOutputUtil.java

示例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);
	}
}
 
開發者ID:PathVisio,項目名稱:pathvisio,代碼行數:30,代碼來源:GpmlFormat2010a.java

示例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);
    }
}
 
開發者ID:Ekryd,項目名稱:sortpom,代碼行數:21,代碼來源:XmlOutputGenerator.java

示例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;
}
 
開發者ID:brunyuriy,項目名稱:crystalvc,代碼行數:20,代碼來源:XMLTools.java

示例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));
}
 
開發者ID:QuinnFreedman,項目名稱:THINK-VPL,代碼行數:24,代碼來源:SaveFileIO.java

示例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...)
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:NetbeansBuildActionJDOMWriterTest.java

示例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 );
}
 
開發者ID:javiersigler,項目名稱:apache-maven-shade-plugin,代碼行數:19,代碼來源:MavenJDOMWriter.java

示例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());
    }
}
 
開發者ID:dirmeier,項目名稱:lvm4j,代碼行數:34,代碼來源:File.java

示例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);      
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:13,代碼來源:ExportMeasurementType.java

示例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));
	}
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:33,代碼來源:RuleBaseCreator.java

示例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"));
}
 
開發者ID:scify,項目名稱:TalkAndPlay,代碼行數:10,代碼來源:XMLConfigurationHandler.java

示例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();
        }
    }
 
開發者ID:pdsoftplan,項目名稱:zap-maven-plugin,代碼行數:13,代碼來源:AlertsFile.java

示例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();
}
 
開發者ID:PathVisio,項目名稱:pathvisio,代碼行數:15,代碼來源:DgpmlOutputter.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:JDOMUtil.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:XMLOutputterTest.java


注:本文中的org.jdom.output.XMLOutputter.setFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。