0

我使用以下代码编写xml

    import nu.xom.Document;
    import nu.xom.Element;
    import nu.xom.Serializer;

    Element root = new Element("ADT");
    root.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema");
    root.setNamespaceURI("urn:hl7-org:v3");

    Element msh = new Element("MSH", "urn:hl7-org:v3");
    Element msh_1 = new Element("MSH.1", "urn:hl7-org:v3");
    msh_1.appendChild(m.getFieldSeperator());
    Element msh_2 = new Element("MSH.2", "urn:hl7-org:v3");
    msh_2.appendChild(m.getEncodingCharacters());

    msh.appendChild(msh_1);
    msh.appendChild(msh_2);

    root.appendChild(msh);
    Document document = new Document(root);
    Serializer serializer;
    serializer = new Serializer(System.out, "UTF-8");
    serializer.setIndent(4);
    serializer.write(document);

这会在控制台上打印出我的 xml 文档,并且打印效果很好。如果有人可以帮助我获得相同的 xml 文件?谢谢

4

1 回答 1

3
FileOutputStream fileOutputStream = new FileOutputStream ("out.xml")
serializer = new Serializer(fileOutputStream, "UTF-8");
serializer.setIndent(4);
serializer.write(document);
//close fileOutputStream  ...
于 2014-10-23T20:06:45.013 回答