Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Conversion ASCII text file->XML

843834Mar 6 2002 — edited Mar 10 2002
I have a flat ASCII log-file looking something like:

----10/18/02 10:30 err: 10/15 ApplicationX(/dir/subdir1)
Desc:IOError file not exist
Filename test.txt
---- 10/18/02 11:00 err: 0/0 ApplicationY(/dir/subdir2)
Desc:SQLError 204
No contact to Database
Network error
----- 10/18/02 11:05 err: 0/0 ApplicationW(/dir/subdir4)
Desc:SNMP request failed
000 00 01 08 03 32
001 08 04 44 43 19

I want to convert this to XML

<errors>
<error>
<date>10/18/02</date>
<time>11:00</time>
<error>10</error>
<level>15</level>
<application>ApplicationX<application>
<path>/dir/subdir1</path>
<description>IOError: File not exist
Filename test.txt
<hexdump></hexdump>
<description>
<error>
<error>
...
<error>
...

<errors>

As can be seen the hexdump is an optional element.

The log files might vary a bit, so I would like a flexible mapping between the text file and the XML.

I imagine the following elements:

1) A mapping file telling what how to parse between the
text file and the XML file. I guess splitting this up in small rules. Maybe this should also be an XML file?

Ideas are welcome.

2) A DTD or XML schema to validate the format after parsing.

I have downloaded Sun's Schema Multi Validator, but
have no experience with this package.

Is it possible to validate a document in memory or is It
required to dump and read the XML-file again before validating? This would slow down the process.

3) Which class should be used to read the data into memory?

I imagine a class implementing the org.w3c.dom.Document interface from the jaxp API.

Other ideas welcome.

4) Would it be beneficial to extend the javax.xml.parsers.DocumentBuilder class and overwrite the parse method in order to parse the log-file?

An answer to just one of the questions are very welcome.

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2002
Added on Mar 6 2002
1 comment
199 views