XML file writting ...

hi all :wink:

e*

Hey Eloi,

Yes you can write new settings with ofXML
just use any one of these:

void setValue(string tag, float valueAsfloat);
void setValue(string tag, int valueAsInt);
void setValue(string tag, string valueAsString);

then followed by:
void saveFile(string xmlFile);

For the tag you can write something that doesn’t exist and it will add it in.
Like.

“Event01:Time”

which will make a tag like

  
<Event01>  
       <Time>  
          some time here  
       </Time>  
</Event01>  

Is that what you were after?
Theo

totally :wink: i was looking into xmlparser.cpp and found out how to make a new file … but that’s easier :wink: thanks for clearance !!

I have tried adding ofXML to my project in Xcode but get these GLvoid errors in ofGraphics that I don’t know what to do with.

Anyway, I’d like to write a XML file from my project, with statistics from the program more or less. Could someone please explain how to get this to work in more detail? I think I might just have messed up with the references in Xcode…

happy to help you get it setup

GLvoid errors in ofGraphics that I don’t know what to do with.

do you get these w/ every example, or only when you add ofXml ?

you can try this fix from d3:
http://forum.openframeworks.cc/t/xcode-3.0–leopard-/269/0

basically, we have an issue with different versions of gcc on a mac complaining about something… we need to find a way to identify gcc version with xcode. we will fix this for 0.05…

also, you can post a text file or screenshot of the errors – would be helpful

thanks!
zach

It sounds like you did mess up the references, as the GCC issue is with glu callbacks so I think that is something seperate.

To add ofXML to an existing project you should have the following things.

  
/ofXML  
    /src  
       ofXML.h  
       ofXML.cpp  
    /libs  
       xmlParser.h  
       xmlParser.cpp  

Please note that this is not the ideal way to add addons to a project - we are working a modular sort of addon system - so this is a bit hacky for now

This folder can be put in your libs or addons folder and from there it can be dragged into the sidebar of xcode - choose ‘relative to project’ from the drop down. http://openframeworks.cc/setup/xcode#quirks-relative

Once it is added - you can use it by adding

  
#include "ofXML.h"  

to testApp.h or any other classes you have made.

then in your testApp.h
you can put under the other testApp variables:

  
ofXML xmlSettings;  

and in testApp.cpp - a basic file write example:

  
xmlSettings.initFromFile(ofToDataPath("settings.xml"), "PARAMS");  
xmlSettings.setValue("APP:VALUE1", 2.03334f); //float value  
xmlSettings.setValue("APP:VALUE2", 2003); //int value  
xmlSettings.setValue("APP:VALUE3", "Hello World"); //string value  
xmlSettings.saveFile(ofToDataPath("settings.xml"));  

This will save a xml file with the following structure:

  
<PARAMS>  
      <APP>  
         <VALUE1>  
               2.03334  
         </VALUE1>  
         <VALUE2>  
               2003  
         </VALUE2>  
         <VALUE3>  
               Hello World  
         </VALUE3>  
     </APP>  
</PARAMS>  

We use the ofToDataPath - to make it save the file relative to openFrameworks’ data/ folder.

Hope that helps - and if not please post which xcode version, openFrameworks version, OS X version you are using and the errors you get!

Thanks,
theo

Great, that works, thanks zach and theo! Both with 0.03 and 0.04 and xcode 2.4.1