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
Post a Comment