Skip to main content

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

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 "&", "<" into "<" 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).

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

Source Link
Dean Harding
  • 19.9k
  • 3
  • 54
  • 70

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 "&", "<" into "<" 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).