java 解析没有根节点的类xml文件

时间:2022-10-20 19:31:56
            InputStream is = new FileInputStream(fileName);
              Enumeration<InputStream> streams = Collections.enumeration(
                 Arrays.asList(new InputStream[] {
                     new ByteArrayInputStream("<root>".getBytes()),
                     is,
                     new ByteArrayInputStream("</root>".getBytes()),
                 }));


            SequenceInputStream seqStream = new SequenceInputStream(streams);

//使用xml解析器进行解析           

 Document document = saxReader.read(seqStream);