Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a log file with errors from a migration I am doing of mail systems. I need to take user migration error logs and make them readable for the end user. A log file might contain a hundred errors. Each error is in XML format. There is usually a great deal of extraneous text around the tags but the important stuff is in between the subject and date tags. What is the best way to parse this file and put the output into another file?

message subject march 11 2010 ....more tags

share|improve this question

3 Answers 3

I don't know how you feel about Java, but if you're interested you could check these tutorials out.

Tutorial 1 Tutorial 2

If not, good keywords for Google are Sax parsing and DOM parsing. You can read up on them on Wikipedia if you want the in-depth differences between the two. For dealing with 100 errors I would think the differences between the two would be minimal.

share|improve this answer

Many languages have xml-parsers built in. Depending on your language of choice, you might want to take a look and see what it has to offer.

share|improve this answer
    
Thank you for your response. I believe that is part of my problem. I have taken a look at a few options from bash to python. Your correct that many can parse the text file but few tutorials I have read seem to do little more than discuss transversing the text. I am looking for the nuts and bolts of extracting to another file and that part seems to be missing from what I read. Granted I am fairly new to programming so my vocabulary for searching google may be limiting me. –  rschapman Jul 28 '10 at 3:21

Answer: XSLT

You can write an XSLT or have one written for you that can transform any sourced XML file or text in general into a different text output. Typically XSLT is used to transform XML into a different XML format or into HTML/XHTML but can also be used to generate CSV or other types of plain text output. Now mind you XSLT isn't the most intuitive XML grammar to learn and is quite verbose however it is very powerful and it shouldn't take more than 15 lines or so to create something that would do what you described and extract two pieces of data and place within a plain text file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.