| Main2.java |
1 package testxml; 2 import java.io.FileNotFoundException; 3 import java.io.IOException; 4 5 /** 6 * Main2.java 7 * 8 * 9 * Testing Java Xml Parser 10 * tested with files from 1 kb to 8 MB (-> approx. 150000 Votes) 11 * for files with 1 kb see testsessions below 12 * for files with 8 MB see file: xmltest_00.txt (testsession 1) 13 * 14 * errorhandling optimised (every malformed xml element between start and end will be ignored) 15 * version 1. that means <v>1<v>2</v> is not corrupted: "2" is given back 16 * this version checks for a wellformed xml code with a given string 17 * 18 * not solved <v>2<b></v> gives you "2<b>"string 19 */ 20 21 /** 22 * 23 * @author Funky 24 */ 25 public class Main2 { 26 27 /** 28 * Creates a new instance of Main2 29 */ 30 public Main2() { 31 } 32 33 /** 34 * @param args the command line arguments 35 */ 36 public static void main(String[] args) { 37 38 ReadXml xmls = new ReadXml(); // new reader 39 int testsession = 1; // testsession setter 40 41 /** 42 * testsesson 1: 43 * xmltest_0.txt ... everything ok wellformed xml // id1_v1 num1_v1; id1_v2 num1_v2 id2_v2 num2_v2 :ok 44 * xmltest_1.txt ... endelement v of first element is missing // id1_v2 num1_v2 : OK 45 * xmltest_2.txt ... second endelement id of second element v is missing // id1_v1 num1_v1; id1_v2 num1_v2 :ok 46 * xmltest_3.txt ... endelement v of first element is malformed // assumed return: id1_v2 num1_v2 : OK 47 * xmltest_4.txt ... endelement v of last element is missing // assumed return: id1_v1 num1_v1 : OK 48 * xmltest_5.txt ... endelement v of last element is malformed // assumed return: id1_v1 num1_v1 : OK 49 * xmltest_6.txt ... in fist v there is a malformed b tag // assumed return: all votes, b must be ignored : OK 50 * 51 * testsession 2: 52 * xmltest_7.txt ... assumed return "2" "4" :ok 53 * xmltest_8.txt ... assumed return "2" : ok 54 * 55 */ 56 xmls.doReading("C:\\xmltest_0.txt"); // data from harddisc stets the Main2 xmlstring 57 58 XmlParser_2 test = new XmlParser_2(xmls.getXmlString(),1000000); // sets the parser object with the matching xmlstring 59 // 100000 sets the number of strings 60 test.setElement("v"); // sets the xml element 61 if (testsession == 1){ 62 /** testsession 1: testing of elements with id and nums */ 63 for (int i=0; i < test.getNumOfElements(); i++){ // loop for all "v" elements 64 // 65 XmlParser_2 id = new XmlParser_2(test.getString(i),"id"); // get all "id" elements within "v" i string 66 XmlParser_2 num = new XmlParser_2(test.getString(i),"num"); // get all "num" elements within "v" i string 67 // 68 // //a.setElement("a"); 69 // //b.setElement("b"); 70 // 71 System.out.println("v "+(i+1)+":"); 72 // 73 for (int j=0; j < id.getNumOfElements(); j++){ // loop all id elements (assuming id has the same length as num) 74 // 75 System.out.println(id.getString(j)+" "+ num.getString(j)); 76 // 77 } 78 System.out.println("------"); 79 // 80 // 81 } 82 } 83 /** testsession 2:simple testing of one element */ 84 if (testsession == 2){ 85 for (int i=0; i < test.getNumOfElements(); i++){ // loop for all "elem" elements 86 87 System.out.println("element "+i+":"+test.getString(i)); 88 89 } 90 } 91 92 } 93 94 } 95