从java序列化时,XML文档错误中只允许一个顶级元素

时间:2013-03-31 07:05:07

标签: xml serialization

当我通过存储第一个节点将一个图形从java序列化到xml时,其中存储了xml文件中的剩余节点和边缘。但是当我打开xml文件时,它给出了一个错误“XML文档中只允许一个顶级元素错误处理资源'文件:/// D:/DM1/tro.xml'。第17行,Pos ...

</GraphPanel_-Node><GraphPanel_-Node>
--------------------^

这是代码

 private class Serialize extends AbstractAction {
    XStream xs = new XStream();


        public Serialize(String name) {
            super(name);

        }

        public void actionPerformed(ActionEvent e) {




            ListIterator<Node> iter = nodes.listIterator();
            while (iter.hasNext()) {
                Node n = iter.next();
                try {
                    FileOutputStream fs = new FileOutputStream("D:/DM1/tro.xml",true);
                    if(!n.fnode){
                        xs.toXML(n, fs);
                        }

                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                }
                iter.remove();
            }

            ListIterator<Edge> Eiter = edges.listIterator();
            while (Eiter.hasNext()) {
                Edge edg = Eiter.next();
                try {
                    FileOutputStream fs = new FileOutputStream("D:/DM1/tro.xml",true);
                    xs.toXML(edg, fs);


                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                }
                Eiter.remove();
            }

            ListIterator<Node> Fiter = nodes.listIterator();
            while (Fiter.hasNext()) {
                Node n = Fiter.next();

                try {
                    FileOutputStream fs = new FileOutputStream("D:/DM1/tro.xml",true);
                    if(n.fnode){
                        FirstNode f =new FirstNode("Root");
                    xs.toXML(f, fs);
                    }
                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                }
                Fiter.remove();
            }

}
}

0 个答案:

没有答案