I noticed that a few of you are using TinyXML and I had a question about it. I've easily been able to figure out how to parse xml documents and save changes to xml documents.
I can't find documentation on how to create a new XML document. Create a new xml document with items from my code, rather than read or edit an existing document.
Does anyone know of any resources or have some sample code that can get me going here? I've spent longer than I should on trying to figure out this task.
thanks,
How can I create a new XML file using TinyXML?
Just use your compiler, VC++ parses XML automatically even tho it doesn't recognise the file; somehow it recognises the carriage breaks in the file and translates it like a text file. Find an XML file, edit it in VC++, then save it as a different name but make sure the extension is XML. Test it in Internet Explorer. Easy
Or, since you know how to parse and save an XML file, you could write some kind of editor. Shouldn't take long, especially if you use Irrlicht to create it, you'll even get a nice window rather than DOS
Or, since you know how to parse and save an XML file, you could write some kind of editor. Shouldn't take long, especially if you use Irrlicht to create it, you'll even get a nice window rather than DOS
No, you don't need to do any custom outputting.
This will save the XML in memory to a file.
When you create a new document in memory, instead of specifying a file to load, just send the new TiXMLDoc without any parameters.
This is the doc link: http://www.grinninglizard.com/tinyxmldo ... ument.html
Code: Select all
bool SaveFile (const char *filename) const
When you create a new document in memory, instead of specifying a file to load, just send the new TiXMLDoc without any parameters.
Code: Select all
[color=red] TiXmlDocument ()
Create an empty document, that has no name.
[/color]
TiXmlDocument (const char *documentName)
Create a document with a name. The name of the document is also the filename of the xml.
TiXmlDocument (const std::string &documentName)
Constructor.
Crud, how do I do this again?
Thanks. I seen that, but my XML document that is created is empty. I think I'm having issues with creating a new element.
The code works if the config.xml exists, but for some reason. I can't create that intial element/node.
The code works if the config.xml exists, but for some reason. I can't create that intial element/node.
Code: Select all
TiXmlElement *pElement;
TiXmlDocument xmlDoc(".//config.xml");
if(!xmlDoc.LoadFile()) // Failed to open
xmlDoc = TiXmlDocument();
// Get Settings Element
pElement = xmlDoc.FirstChildElement("settings");
if(!pElement)
{ // Not found, so create new one
pElement = new TiXmlElement("settings");
}
... set each element attribute here code ....
xmlDoc.SaveFile(".//config.xml");