Java 如何更改JAXB Marshaller行分隔符
我想在生成xml时分隔xml行 我的代码:Java 如何更改JAXB Marshaller行分隔符,java,xml,Java,Xml,我想在生成xml时分隔xml行 我的代码: JAXBContext jaxbContext = JAXBContext.newInstance(Student.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty("com.su
JAXBContext jaxbContext = JAXBContext.newInstance(Student.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(student, new File(fileName));
marshaller.marshal(student, System.out);
JAXBContext-JAXBContext=JAXBContext.newInstance(Student.class);
Marshaller=jaxbContext.createMarshaller();
setProperty(marshaller.JAXB_片段,Boolean.TRUE);
setProperty(“com.sun.xml.internal.bind.xmlHeaders”,”;
setProperty(marshaller.JAXB_格式化的_输出,true);
marshaller.marshall(学生,新文件(文件名));
马歇尔(学生,系统,输出);
输出:
预期产出:
我得到了一些关于这个问题的信息:----
值得检查不同类型的线端。当我
第一次编程时,我用的是电传打字机。我不得不推CR=
坎贝尔·里奇在每一行的末尾。然后我不得不推了推
LF=换行=\n键将纸张向上移动。旧版Mac用作\r
行结束序列。DOS和Windows®在最后仍然使用CR-LF(\r\n)
一条线的长度。类Unix系统总是单独使用LF(\n)。这意味着,如果
您正在Linux系统上工作,系统中没有\r字符
普通文本文件。你将不得不做一些事情来考虑
如果将文件传输到Windows®系统,则会出现这种差异
使用\r\n。但我目前正在Windows系统上生成XMl,但仍然
它考虑UNIX并生成(\n)行的结尾。请随便
帮我解决这个问题
请将输出添加为文本。我这次比较了xml文件的显示问题,这就是为什么我这次复制输出时没有显示实际问题的原因,这就是为什么我要附加图像