perhaps my data classes may be of use to you.
http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=781
basically you can use it as a framework for all your data elements. By subclassing from FileDataElement, and defining it according to its rules, you can easily serialise your structure.
It may be a bit complex (definitely at first) but i use it all the time and it makes things a lot easier. For example, in the constructor of a FileDataElement, you specify a tag name, which is used for input/output of xml. the create/restore xml functions are implemented already, (Restore: checking the provided tag’s name against the specified one, Create: creating a tag for you with the correct name already so you only need to add child elements/attributes) - you just implement readDataFrom and addDataTo XmlElement functions. If your structure contains nested elements, they should know what they contain, and can simply add those elements tags during serialisation…
e.g.
class box : public FileDataElement
{
private:
int size;
...
public:
Box ()
: FileDataElement (T("box"))
{
}
...
void addDataToXmlElement (XmlElement* tag)
{
tag->setAttribute (T("size"), size);
}
void readDataFromXmlElement (XmlElement* tag)
{
size = tag->getIntAttribute (T("size"));
}
};
class Room : public FileDataElement
{
private:
OwnedArray<Box> boxes;
...
public:
Room ()
: FileDataElement (T("room"))
{
}
void addDataToXmlElement (XmlElement* tag)
{
for (int i=0; i<boxes.size(); i++)
{
tag->addChildElement (boxes.getUnchecked(i)->createXml());
}
}
void readDataFromXmlElement (XmlElement* tag)
{
XmlElement* subTag = tag->getFirstChildElement ();
while (subTag)
{
if (subTag->hasTagName (T("box")))
{
Box* box = new Box;
box->restoreFromXml (subTag);
boxes.add (box);
}
subTag = subTag->getNextElement ();
}
}
};
You just define how each element can serialise itself, and then they can work together to result in a final big XML structure for you to export.
Have you looked at the example juce plugin? It shows how you can store xml in a patch. It’s right there, you don’t need to use the getChunk/setChunk functions if you’re using the juce audio plugin framework.