i try to write some data in my GUI-Application to an xml File.
My target is to have a simple GUI, where is an editable label, and if i put some Text in there, that the App saves it in a XML File, and if i reopen the app that it reads from the XML File and puts the data back in the Labelfield.
I’m really new to c++ and Juce, but i guess i need to use the XMLElement, XMLDocument and XMLElement::writeToFile functions / classes, right?
May someone could give a simple step by step how they exactly work? The documentation is kind of confusing me.
thank you for your help, i see that i need to go deeper in the basics of c++, to really understand a) your code @cpr , and b) learn how to include the functions from the juce framwork correctly.
again and back to the Problem =) .
I think i have a main Problem with the file creation.
I insert in my Project just the Example from the JUCE XMLElement Class:
/* EXAMPLE STARTS HERE
// create an outer node called "ANIMALS"
XmlElement animalsList (“ANIMALS”);
for (int i = 0; i < numAnimals; ++i)
{
// create an inner element…
XmlElement* giraffe = new XmlElement (“GIRAFFE”);
giraffe->setAttribute (“name”, “nigel”);
giraffe->setAttribute (“age”, 10);
giraffe->setAttribute (“friendly”, true);
// …and add our new element to the parent node
animalsList.addChildElement (giraffe);
}
// now we can turn the whole thing into a text document…
String myXmlDoc = animalsList.createDocument (String());
*/ EXAMPLE ENDS HERE
As i understood, this example would write me an XMLDocument in which includes the Attributes from the Giraffe.
The Code compiles, but i cant find any XML File or Document on my Mac.
Then i thought, i need to write that XMLDocument in an File.
So i thought i need to add the writeToFile function at the end, cause it says it would write the Element to an File as an XML Document.
My Idea:
animalsList.writeToFile();
but what to insert in the brackets??? And where does the programm know, where to store the file? Do i need to define a directory path before i can write something?
Yeah, you should give that a File with a full path where you want the file written. You shouldn’t do something like myxml.writeToFile(File(“mydocument.xml”),String()); because the file can end up in some unexpected place. (Just a file name by itself does NOT mean the directory where your program executable is, it means the “working directory”.)