What's todays (10-2017) common way to have a config.xml/.json to position several elements on cavas?

Hello there,

I’m quite new to openFrameworks and having some troubles to find a good way to store “settings” in an accessable file outside of my openFrameworks .cpp files.

There are so many options offered but non of those I could get working for my case. I would like to have an file like this

<videos>
        <video x="0" y="0" file="1.mov"/>
        <video x="200" y="0" file="2.mov"/>
        <video x="400" y="100" file="3.mov"/>
</videos>

JSON would be also fine:

videos: [
   {x: 0, y: 100, file: "1.mov"},
   {x: 400, y: 100, file: "2.mov"},
   {x: 800, y: 100, file: "3.mov"}
]

I tried the ofxXMLsettings, plain ofXML, ofxJSONsettings (and some more I can’t remember). Some of those didn’t had the functionality to loop over an “array” of videos. Some other should have it, but did not work for me.

In general it’s a bit confusing to me, what’s TODAYS best way to do it. As i understood for example the ofxXMLsettings is outdated and somehow replaced by “native” ofXML functionality.

Can anyone give me a kickstart?

Thanks alot in advance,
Hans

Hi,
Not sure about what are common and modern practices, but I have no problem with ofxXmlSettings:

ofxXmlSettings xml;
xml.load("test.xml");
xml.pushTag("videos");
int num = xml.getNumTags("video");
for( int i = 0; i < num; i++ )
{
    int x = xml.getAttribute("video", "x", 0, i);
    int y = xml.getAttribute("video", "y", 0, i);
    string filename = xml.getAttribute("video", "file", "", i);
    cout << x << " " << y << " " << filename << endl;
}
xml.popTag();

Hi,
If it’s not a problem to have:

<videos>
    <video1>
    <video2>
    ...
</videos>

you can use something like this:

ofxXmlSettings settings;
settings.loadFile("settings.xml");

settings.setValue("settings:videos:video1", "1.mov");
settings.setAttribute("settings:videos:video1", "x", 0, 0);
settings.setAttribute("settings:videos:video1", "y", 0, 0);
				
settings.setValue("settings:videos:video2", "2.mov");
settings.setAttribute("settings:videos:video2", "x", 200, 0);
settings.setAttribute("settings:videos:video2", "y", 0, 0);

settings.saveFile("settings.xml");

The result

<videos>
        <video1 x="0" y="0">1.mov</video1>
        <video2 x="200" y="0">2.mov</video2>
</videos>

It’s only a simple example. You can iterate it in for loop, you can save file as an attribute etc

Thanks alot! Got it working with the ofxXmlSettings example provided by lilive