Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am currently in a task to generate an XML file for an srt text file containing timestamps and corresponding text. To generate an exe file which accepts file name input and outputs the relevant XML file to be used as part of an automated script.

Is it Advisable to use Tinyxml for this?

Edit:

your comments regarding this are very much appreciated what's the easiest way to generate xml in c++?

share|improve this question
1  
May I recommend TiCpp: code.google.com/p/ticpp This is a C++ interface over Tiny Xml. The iterator style is a bit weird, but it is much more natural for C++ programming. –  Matthieu M. Mar 20 '11 at 19:51
add comment

3 Answers

up vote 6 down vote accepted

Generating an XML file is a different task to consuming an XML file. If you're just generating an XML file in a specific format with fairly simple inputs, then it's not too much work to just do something like:

mystream << "<xmldata>" << endl;
mystream << "<something>Blah</something>" << endl;
mystream << "</xmldata>" << endl;

That's probably going to be much simpler than building a TinyXML object model, populating it and then writing it out.

The only thing you need to worry about is proper escaping (i.e. turning "&" into "&amp;", "<" into "&lt;" and so on).

Now, if you were parsing an XML file, then I would definitely recommend using a third-party library (and TinyXML is a good one if you don't need XSLT or schema validation, etc).

share|improve this answer
    
While it's easier, I'd still recommend using a proper XML library just so you don't need to worry about escaping things. If you get it wrong, people will have issues trying to consume your XML somewhere down the track when some edge case crops up. –  Matthew Scharley Mar 14 '11 at 6:15
    
@Matthew would saving the file in correct encoding be an issue? does encoding differ in Linux environment –  Aditya P Mar 14 '11 at 6:24
    
@AdityaGameProgrammer I'm not a C++ programmer so I can't answer that one for you sorry. That said, encodings are another tricky issue, one that should be transparent and not an issue if you use a proper library. –  Matthew Scharley Mar 14 '11 at 6:26
1  
@AdityaGameProgrammer: Line endings work just like any other text file on Windows vs. Linux. Encodings like UTF-8 vs. ISO-8859-1 or whatever are handled similarly, though I would suggest there's little reason to encode XML files in anything but UTF-8. –  Dean Harding Mar 14 '11 at 8:35
    
@Dean Harding: I would suggest writing a small framework around it still. Just to make sure that escaping is done correctly and tags get closed properly... Might as well use a simple library at that point ? Oh and by the way, don't use endl all over the place. –  Matthieu M. Mar 20 '11 at 19:54
show 3 more comments

I see no reason to reinvent the wheel when you just can use a library.

The little performance boost you may gain by writing your own parsing code is nothing compared to the overhead of rolling your own vs. using a library.

Anyway, what you describe is not parsing. It's generating an XML file. At which point, using a XML library could be overkill.

share|improve this answer
add comment

You can also use this xml library.

To answer your question : don't waste your time on something that is already done and works fine.

share|improve this answer
add comment

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.