English 中文(简体)
A. 与斯塔尔·安森特的登革热问题
原标题:Indentation issues with Staxmate API

我正在利用Staxmate AP生成XML档案。 http://staxmate.codehaus.org/Tutorial"rel=“nofollow noreferer”>。 我试图修改我的法典。 最后,我补充说:

doc.setIndentation("
  ", 1, 1);

是什么原因造成新产生的XML档案空洞! 如果不采用这种方法,整个XML档案就会按预期产生。

在项目构造中检查一些鱼类,我在同一包裹中设置了一个试验组,其代码为:

package ch.synlogic.iaf.export;

import java.io.File;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;

import org.codehaus.staxmate.SMOutputFactory;
import org.codehaus.staxmate.out.SMOutputDocument;
import org.codehaus.staxmate.out.SMOutputElement;

public class Test {

public static void main(String[] args) {
 main("c:\tmp\empl.xml");
}

public static void main(String fname)
{
 // 1: need output factory
 SMOutputFactory outf = new SMOutputFactory(XMLOutputFactory.newInstance());
 SMOutputDocument doc;
 try {
  doc = outf.createOutputDocument(new File(fname));

 // (optional) 3: enable indentation (note spaces after backslash!)
 doc.setIndentation("
  ", 1, 1);
 // 4. comment regarding generation time
 doc.addComment(" generated: "+new java.util.Date().toString());
 SMOutputElement empl = doc.addElement("employee");
 empl.addAttribute(/*namespace*/ null, "id", 123);
 SMOutputElement name = empl.addElement("name");
 name.addElement("first").addCharacters("Tatu");
 name.addElement("last").addCharacters("Saloranta");
 // 10. close the document to close elements, flush output
 doc.closeRoot();
 } catch (XMLStreamException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
}
}

现在,当我从我的法典中援引<代码>main(String)方法时,问题依然存在,而如果我只是管理阶层,问题依然存在。 测试是顺利进行的。 我的守则涉及数据库的初始化和其他一些产品具体行动。

我失去了任何想法,看我如何这样做?

最佳回答

A. 与森林产品协会的合作

WstxOutputFactory factory = new WstxOutputFactory();
factory.setProperty(WstxOutputFactory.P_AUTOMATIC_EMPTY_ELEMENTS, true);
SMOutputFactory outf = new SMOutputFactory(factory);
doc = outf.createOutputDocument(fout);
doc.setIndentation("
  ", 1, 1);
问题回答

Below works for me - context.setIndentation(" ", 2, 1); // indent by windows lf and 1 tab per level





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签