本文整理汇总了Java中org.jdom2.output.XMLOutputter.output方法的典型用法代码示例。如果您正苦于以下问题:Java XMLOutputter.output方法的具体用法?Java XMLOutputter.output怎么用?Java XMLOutputter.output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.output.XMLOutputter
的用法示例。
在下文中一共展示了XMLOutputter.output方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sloppyPrint
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Creates an outputter and writes an XML tree.
*
* The encoding argument here only sets an attribute in the
* XML declaration. It's up to the caller to ensure the writer
* is encoding bytes to match. If encoding is null, the default
* is "UTF-8".
*
* If XML character entity escaping is allowed, otherwise unmappable
* characters may be written without errors. If disabled, an
* UnmappableCharacterException will make their presence obvious and fatal.
*
* LineEndings will be CR-LF. Except for comments!?
*
* @param doc
* @param writer
* @param disableEscaping
*/
public static void sloppyPrint( Document doc, Writer writer, String encoding, boolean allowEscaping ) throws IOException {
Format format = Format.getPrettyFormat();
format.setTextMode( Format.TextMode.PRESERVE ); // Permit leading/trailing space.
format.setExpandEmptyElements( false );
format.setOmitDeclaration( false );
format.setIndent( "\t" );
format.setLineSeparator( LineSeparator.CRNL );
if ( encoding != null ) {
format.setEncoding( encoding );
}
if ( !allowEscaping ) {
format.setEscapeStrategy(new EscapeStrategy() {
@Override
public boolean shouldEscape( char ch ) {
return false;
}
});
}
XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
outputter.output( doc, writer );
}
示例2: exportXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public void exportXML(ArrayList<Pokemon> pokemons,String tipo){
try {
Element pokemon = new Element("pokemon");
Document doc = new Document(pokemon);
for(Pokemon p:pokemons) {
Element poke = new Element("pokemon");
poke.addContent(new Element("nombre").setText(p.getName()));
poke.addContent(new Element("peso").setText(String.valueOf(p.getWeight())));
poke.addContent(new Element("altura").setText(String.valueOf(p.getHeight())));
poke.addContent(new Element("base_experience").setText(String.valueOf(p.getBaseExperience())));
doc.getRootElement().addContent(poke);
}
XMLOutputter output = new XMLOutputter();
output.setFormat(Format.getPrettyFormat());
output.output(doc, new FileWriter("pokemons-tipo-"+tipo+".xml"));
}catch(Exception e) {
System.out.println("Ocurri� alg�n error");
}
}
示例3: updateXMLValue
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* This method updates XML values from the Health Check GUI.
* Not all items are supported. If it can't find the XML file,
* it will print the error message. Could cause errors if the structure
* of the XML file has been modified.
*/
public void updateXMLValue(String item, String value) {
if (item.equals("jss_url")){
this.root.getChildren().get(0).setText(value);
} else if (item.equals("jss_username")){
this.root.getChildren().get(1).setText(value);
} else if (item.equals("jss_password")){
this.root.getChildren().get(2).setText(value);
} else if (item.equals("smart_groups")){
this.root.getChildren().get(5).getChildren().get(1).setText(value);
} else if (item.equals("extension_attributes")){
this.root.getChildren().get(5).getChildren().get(2).getChildren().get(0).setText(value);
this.root.getChildren().get(5).getChildren().get(2).getChildren().get(1).setText(value);
}
try {
XMLOutputter o = new XMLOutputter();
o.setFormat(Format.getPrettyFormat());
o.output(this.root, new FileWriter(getConfigurationPath()));
} catch (Exception e) {
LOGGER.error("Unable to update XML file.", e);
}
}
示例4: doGetPost
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Override
protected void doGetPost(MCRServletJob job) throws Exception {
HttpServletRequest request = job.getRequest();
// get base url
if (this.myBaseURL == null) {
this.myBaseURL = MCRFrontendUtil.getBaseURL() + request.getServletPath().substring(1);
}
logRequest(request);
// create new oai request
OAIRequest oaiRequest = new OAIRequest(fixParameterMap(request.getParameterMap()));
// create new oai provider
OAIXMLProvider oaiProvider = new JAXBOAIProvider(getOAIAdapter());
// handle request
OAIResponse oaiResponse = oaiProvider.handleRequest(oaiRequest);
// build response
Element xmlRespone = oaiResponse.toXML();
// fire
job.getResponse().setContentType("text/xml; charset=UTF-8");
XMLOutputter xout = new XMLOutputter();
xout.setFormat(Format.getPrettyFormat().setEncoding("UTF-8"));
xout.output(addXSLStyle(new Document(xmlRespone)), job.getResponse().getOutputStream());
}
示例5: toXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Test
public void toXML() throws Exception {
JAXBContext jc = JAXBContext.newInstance(MCRNavigationItem.class);
Marshaller m = jc.createMarshaller();
JDOMResult JDOMResult = new JDOMResult();
m.marshal(this.item, JDOMResult);
Element itemElement = JDOMResult.getDocument().getRootElement();
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
out.output(itemElement, System.out);
assertEquals("template_mysample", itemElement.getAttributeValue("template"));
assertEquals("bold", itemElement.getAttributeValue("style"));
assertEquals("_self", itemElement.getAttributeValue("target"));
assertEquals("intern", itemElement.getAttributeValue("type"));
assertEquals("true", itemElement.getAttributeValue("constrainPopUp"));
assertEquals("false", itemElement.getAttributeValue("replaceMenu"));
assertEquals("item.test.key", itemElement.getAttributeValue("i18nKey"));
Element label1 = itemElement.getChildren().get(0);
Element label2 = itemElement.getChildren().get(1);
assertEquals("Deutschland", label1.getValue());
assertEquals("England", label2.getValue());
}
示例6: write
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Write the root Element to a writer.
*
* @param root
* Root Element to write.
* @param writer
* Writer to write to.
* @throws IOException
* if the writer fails to write.
*/
@SuppressWarnings("unchecked")
protected void write(Element root, Writer writer) throws IOException {
XMLOutputter outputter = new XMLOutputter();
outputter.setFormat(Format.getPrettyFormat());
Document document = new Document(root);
if (stylesheetURL != null) {
Map<String, String> instructionMap = new HashMap<String, String>(2);
instructionMap.put("type", "text/xsl");
instructionMap.put("href", stylesheetURL);
ProcessingInstruction pi = new ProcessingInstruction(
"xml-stylesheet", instructionMap);
document.getContent().add(0, pi);
}
outputter.output(document, writer);
}
示例7: createXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Test
public void createXML() {
MCRMetaISO8601Date ts = new MCRMetaISO8601Date("servdate", "createdate", 0);
String timeString = "1997-07-16T19:20:30.452300+01:00";
ts.setDate(timeString);
assertNotNull("Date is null", ts.getDate());
Element export = ts.createXML();
if (LOGGER.isDebugEnabled()) {
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
StringWriter sw = new StringWriter();
try {
xout.output(export, sw);
LOGGER.debug(sw.toString());
} catch (IOException e) {
LOGGER.warn("Failure printing xml result", e);
}
}
}
示例8: derivates
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
@Test
public void derivates()
throws JDOMException, IOException, TransformerFactoryConfigurationError, TransformerException {
String testFilePath = "/" + getClass().getSimpleName() + "/xml/derivateObj.xml";
InputStream testXMLAsStream = getClass().getResourceAsStream(testFilePath);
// JDOMResult jdomResult = xslTransformation(testXMLAsStream, "/" + getClass().getSimpleName() + "/xsl/mcr2solrOld.xsl");
JDOMResult jdomResult = xslTransformation(testXMLAsStream);
Document resultXML = jdomResult.getDocument();
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
xmlOutputter.output(resultXML, System.out);
List<Element> mycoreojectTags = XPathFactory.instance()
.compile("/solr-document-container/source/mycorederivate", Filters.element()).evaluate(resultXML);
assertEquals(1, mycoreojectTags.size());
}
示例9: createOPFContent
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static byte[] createOPFContent(Book book) throws IllegalArgumentException, IllegalStateException
{
Document opfDocument = write(book);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
try
{
outputter.output(opfDocument, baos);
}
catch (IOException e)
{
logger.error("", e);
}
return baos.toByteArray();
}
示例10: main
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Document document = new SAXBuilder().build(new File("data/project.mods.xml"));
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
BufferedWriter bufferedWriter = null;
try {
bufferedWriter = new BufferedWriter(new FileWriter("data/cdata.project.mods.xml"));
out.output(new SAXBuilder().build(new StringReader(xmlOutputter(document, "xslt/cdata.xsl", null))),bufferedWriter);
}
finally {
if (bufferedWriter != null) {
bufferedWriter.close();
}
}
}
示例11: outputXHTMLDocument
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static byte[] outputXHTMLDocument(Document document)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
document.setDocType(Constants.DOCTYPE_XHTML.clone());
XMLOutputter outputter = new XMLOutputter();
Format xmlFormat = Format.getPrettyFormat();
outputter.setFormat(xmlFormat);
outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
outputter.output(document, baos);
}
catch (IOException e)
{
logger.error("", e);
}
return baos.toByteArray();
}
示例12: saveSettings
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
protected void saveSettings( final String xmlFilename ) throws IOException
{
final Element root = new Element( "Settings" );
Element viewerPNode = new Element( "viewerP" );
Element viewerQNode = new Element( "viewerQ" );
root.addContent( viewerPNode );
root.addContent( viewerQNode );
viewerPNode.addContent( viewerP.stateToXml() );
viewerQNode.addContent( viewerQ.stateToXml() );
root.addContent( setupAssignments.toXml() );
root.addContent( bookmarks.toXml() );
final Document doc = new Document( root );
final XMLOutputter xout = new XMLOutputter( Format.getPrettyFormat() );
xout.output( doc, new FileWriter( xmlFilename ) );
}
示例13: patch
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public static void patch(InputStream target, InputStream diff,
OutputStream result) throws IOException {
try {
Document targetDoc = XmlHelper.parse(target);
Document diffDoc = XmlHelper.parse(diff);
Element diffRoot = diffDoc.getRootElement();
for (Object o : diffRoot.getChildren()) {
patch(targetDoc, (Element) o);
}
XMLOutputter outputter = new XMLOutputter();
// Use the separator that is appropriate for the platform.
Format format = Format.getRawFormat();
format.setLineSeparator(System.getProperty("line.separator"));
outputter.setFormat(format);
outputter.output(targetDoc, result);
} catch (JDOMException e) {
throw new PatchException(ErrorCondition.INVALID_DIFF_FORMAT, e);
}
}
示例14: CrearXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
public CrearXML(String file) {
Element datos = new Datos("default");
Document doc = new Document(datos);//Creamos el documento
try {
XMLOutputter out = new XMLOutputter();
FileOutputStream salida = new FileOutputStream(file);
out.output(doc, salida);
salida.flush();
salida.close();
//out.output(doc, System.out);
} catch (Exception e) {
}
}
示例15: buildSettingsXML
import org.jdom2.output.XMLOutputter; //导入方法依赖的package包/类
/**
* Read {@code baseFilename.settings.xml} into a string if it exists.
*
* @return contents of {@code baseFilename.settings.xml} or {@code null} if
* that file couldn't be read.
*/
private static String buildSettingsXML( final String baseFilename )
{
final String settings = baseFilename + ".settings.xml";
if ( new File( settings ).exists() )
{
try
{
final SAXBuilder sax = new SAXBuilder();
final Document doc = sax.build( settings );
final XMLOutputter xout = new XMLOutputter( Format.getPrettyFormat() );
final StringWriter sw = new StringWriter();
xout.output( doc, sw );
return sw.toString();
}
catch ( JDOMException | IOException e )
{
LOG.warn( "Could not read settings file \"" + settings + "\"" );
LOG.warn( e.getMessage() );
}
}
return null;
}