1
2 package org.catacomb.serial.xml;
3
4 import org.catacomb.report.E;
5
6
7
8
9 public class XMLChecker {
10
11
12
13 public static void checkXML(String s, boolean bshow) {
14 long starttime = System.currentTimeMillis();
15 XMLTokenizer tkz = new XMLTokenizer(s);
16 int nerror = 0;
17 int nread = 0;
18
19 while (true) {
20 XMLToken xmlt = tkz.nextToken();
21 if (bshow) {
22 System.out.println("item " + nread + " " + xmlt);
23 }
24 nread++;
25 if (xmlt.isNone()) {
26 break;
27 }
28 }
29 long endtime = System.currentTimeMillis();
30
31 System.out.println(" Total tags: " + nread + "\n total errors: " + nerror +
32 "\n tokenizing took " + (int)(endtime - starttime) + " ms");
33 }
34
35
36
37
38
39
40
41
42 public static String deGarbage(String sin) {
43 String s = sin;
44 if (s.startsWith("<")) {
45
46
47 } else {
48 int iob = s.indexOf("<");
49
50 if (iob > 0) {
51 String junk = s.substring(0, iob);
52 if (junk.trim().length() > 0) {
53
54 System.out.println("WARNING - garbage at start of xml file - first < is at " +
55 iob + " preceded by ---" + junk + "---");
56 }
57 s = s.substring(iob, s.length());
58
59 } else {
60 E.error(" - xml file contains no xml " + s);
61 s = null;
62 }
63 }
64
65 return s;
66 }
67
68
69
70
71 }
72
73