2

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++?

asked Mar 14, 2011 at 5:28
1
  • 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. Commented Mar 20, 2011 at 19:51

3 Answers 3

7

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).

answered Mar 14, 2011 at 6:04
8
  • 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. Commented Mar 14, 2011 at 6:15
  • @Matthew would saving the file in correct encoding be an issue? does encoding differ in Linux environment Commented Mar 14, 2011 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. Commented Mar 14, 2011 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. Commented Mar 14, 2011 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. Commented Mar 20, 2011 at 19:54
5

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.

answered Mar 14, 2011 at 6:03
2

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.

answered Mar 14, 2011 at 9:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.