java - Convert from txt to xml -


i have java code convert txt file xml file: (it works)

pattern p = pattern.compile(".+@.+\\.[a-z]+"); bufferedreader in = new bufferedreader(new filereader(fromfile)); fileoutputstream fos = new fileoutputstream(tofile); outputformat of = new outputformat("xml", "windows-1250", true); of.setindent(1); of.setindenting(true); xmlserializer serializer = new xmlserializer(fos, of); contenthandler hd = serializer.ascontenthandler(); hd.startdocument();     attributesimpl atts = new attributesimpl();     hd.startelement("", "", "cdr_files", atts);     string line = null, tag;     while ((line = in.readline()) != null) {         if (line.equals("cdr file")) {             line = in.readline();             hd.startelement("", "", "cdr", atts);             int = 0;             while (!line.equals("cdr file")) {               if (i == 0)                 tag = "record_no";               else if (i == 1)                 tag = "time";               else if (i == 2)                 tag = "serial_number";               else if (i == 3)                 tag = "serial_number_in_module"; 

this txt file:

cdr file 1 time=2010/02/15 17:15:17  serial_number=1924891018 serial_number_in_module=282826228ff cdr file 2 time=2010/02/15 17:15:17  serial_number=1924891018 serial_number_in_module=283423627ff ... 

i have 2 letters "ff" in serial_number_in_module, dont need save in xml file. possible not save letters?

you string file while reading , write condition serial number

example

string sample = "282826228ff"; string output = sample.replaceall("\\d+",""); 

output: 282826228


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -