Java : Read multiple xml from a single text file and store them as a List -



Java : Read multiple xml from a single text file and store them as a List<string> -

consider next text file content :

<testfile> <testfile_id>654316</testfile_id> <testvin>ere</testvin> <testtype_er>fd 91 mux</testtype_er> <test_rt> <test41_long_cs>b001_001_001</test41_long_cs> </test_rt> </testfile> <testfile> <testfile_id>654317</testfile_id> <testvin>dfg</testvin> <testtype_er>fd 91 mux</testtype_er> <test_rt> <test44_long_cs>b001_001_001</test44_long_cs> </test_rt> </testfile> <testfile> <testfile_id>654318</testfile_id> <testvin>dfgd</testvin> <testtype_er>fd 91 mux</testtype_er> <test_rt> <test43_long_cs>b001_001_001</test41_long_cs> </test_rt> <test_rt> <test42_long_cs>b001_001_001</test41_long_cs> </test_rt> </testfile>

i tried reading above file in java , store each xml objects ( begins <testfile> , ends </testfile> ) separate objects in list<string>. tried next code:

public static list<string> readmessagestest() throws filenotfoundexception { list<string> messagelist = new arraylist<string>(); string content = ""; seek { content = new scanner(new file("d:\\public\\testfile.txt")).usedelimiter("\\z").next(); }catch(exception e){ e.printstacktrace(); } messagelist.add(content); homecoming messagelist; }

the above code reads entire xml text in file , need split string , manually add together list.. can please suggest me easy solution rather doing way ?

java xml file-io xml-parsing java-7

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -