我试图使用BufferWriter编写xml标签但是,当我尝试打开一个文件时,它显示为空页面。代码如下

bw.write("<?xml version=" + "\"1.0\"" + " " + "encoding=" + "\"UTF-8\""
                + "?>");
        bw.newLine();
        bw.write("<con:soapui-project activeEnvironment=" + "\"Default\"" + " "
                + " name=" + "\"REST Project 1\"" + " " + "soapui-version="
                + "\"4.6.4\"" + " " + "xmlns:con="
                + "\"http://eviware.com/soapui/config\"" + ">");
        bw.newLine();
        bw.write("<con:settings/>");
        bw.newLine();
        bw.write("<con:interface xsi:type=" + "\"con:RestService\"" + " "
                + "wadlVersion=" + "\"http://wadl.dev.java.net/2009/02\"" + " "
                + "name=" + "\"" + baseUrl1 + "\"" + "" + " " + "type="
                + "\"rest\"" + " " + "xmlns:xsi="
                + "\"http://www.w3.org/2001/XMLSchema-instance\"" + ">");
        bw.newLine();
        bw.write("<con:settings/>");


我可以像上面那样写xml标记吗,或者有什么办法可以写xml标记?

最佳答案

为什么要重新发明轮子?您可以使用JAXB并搜索marshalling

对于初学者,您可以参考this

10-07 22:42