ofxXmlSettings
ofxXmlSettings addon allows for reading and writing of xml files in openFrameworks. Most commonly xml settings are used for storing settings between closing and launching apps. XML has the advantage of being easy for people to read and edit but still convenient for manipulating with code.
An xml document is composed of tags with values and other tags inside of them. A tag has a name, attributes, values. If a tag contains other tags they are called its children. If a tag is inside of another, the enclosing tag is called its parent. The tags next to one another are siblings.
<parentTagName
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &value)Adds a new attribute to the tag with with the given string value.
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &value, int which=0)Adds a new attribute to the tag with the given string value.
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int value)Adds a new attribute to the tag with with the given int value.
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double value)Adds a new attribute to the tag with with the given double value.
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int value, int which=0)Adds a new attribute to the tag with with the given int value. If the tag doesn't exist it is created. If an attribute at index 'which' already exists its value replaced by the provided value
addAttribute( ... )
int addAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double value, int which=0)Adds a new attribute to the tag with the given double value.
addTag( ... )
int addTag(const __cxx11::string &tag)Adds an empty tag at the current document level. If you want to add children tags, call pushTag afterwords to begin editing the document with the new tag as root.
Return the number of tags with the same name at the current level.
addValue( ... )
int addValue(const __cxx11::string &tag, const __cxx11::string &value)Adds a tag with tag name and string value to the document, returning the number of tags with the same name.
addValue( ... )
int addValue(const __cxx11::string &tag, int value)Adds a tag with tag name and integer value to the document, returning the number of tags with the same name.
addValue and setValue are very similar, both add new tags to the current document with the given name and value. The distinction is that if tags exist with the same name at the current document level, addValue will create additional tags, while setValue will replace contents of the tags based on the 'which' parameter.
addValue( ... )
int addValue(const __cxx11::string &tag, double value)Adds a tag with tag name and double value to the document, returning the number of tags with the same name.
attributeExists( ... )
bool attributeExists(const __cxx11::string &tag, const __cxx11::string &attribute, int which=0)Returns true if a tag has any attributes.
clear( )
void clear()Removes all tags at the current document level.
clearTagAttributes( ... )
void clearTagAttributes(const __cxx11::string &tag, int which=0)Clears all attributes from the given tag name and tag index which.
clearTagContents( ... )
void clearTagContents(const __cxx11::string &tag, int which=0)If the given tag exists at the current pushTag level set its contents to empty.
copyXmlToString( ... )
void copyXmlToString(__cxx11::string &str)Copies the contents of the ofxXmlSettings into the string str.
getAttribute( ... )
__cxx11::string getAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &defaultValue, int which=0)Returns the value of the attribute on tag at index which as a string.
getAttribute( ... )
int getAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int defaultValue, int which=0)Returns the value of the attribute on tag at index which as an int.
getAttribute( ... )
double getAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double defaultValue, int which=0)Returns the value of the attribute on tag at index which as a double.
getAttributeNames( ... )
bool getAttributeNames(const __cxx11::string &tag, int &outNames, int which=0)Returns an array of strings containing all attribute names on the tag. This is useful in conjunction with a loop to get all values of the tags one by one with calls to getAttribute.
getElementForAttribute( )
int * getElementForAttribute()getNumAttributes( ... )
int getNumAttributes(const __cxx11::string &tag, int which=0)Returns the number of attributes on a tag at index which.
getNumTags( ... )
int getNumTags(const __cxx11::string &tag)Returns the number of tags with the given name at the current document level. Useful for iterating through a list of sibling tags with the same name.
getPushLevel( )
int getPushLevel()getPushLevel returns the number of tags that have been pushed. Starting at 0 when the file is first populated (eg a call to loadFile). Each time pushTag is called push level increases by one. Each time popTag is called it decreases.
getValue( ... )
__cxx11::string getValue(const __cxx11::string &tag, const __cxx11::string &defaultValue, int which=0)Returns the value stored by the requested tag as a string. Refer above for description of how this method works.
getValue( ... )
int getValue(const __cxx11::string &tag, int defaultValue, int which=0)Returns the value stored by the requested tag. The data type returned depends on the type provided as the defaultArgument. For example, if the tag is:
<myTag
getValue( ... )
double getValue(const __cxx11::string &tag, double defaultValue, int which=0)Returns the value stored by the requested tag as a double. Refer above for description of how this method works.
load( ... )
bool load(const __cxx11::string &path)loadFile( ... )
bool loadFile(const __cxx11::string &xmlFile)Loads and parses the xml file at the given path. Returns true if the file is found and is correctly formatted xml.
loadFromBuffer( ... )
bool loadFromBuffer(__cxx11::string buffer)Populates the ofxXmlSettings object from a string of containing xml.
ofxXmlSettings( ... )
ofxXmlSettings(const __cxx11::string &xmlFile)Initializes an xml settings object and loads the file at xmlFile path.
ofxXmlSettings( )
ofxXmlSettings()Default constructor for ofxXmlSettings. Initializes an empty object with no file set or loaded and no contents.
popTag( )
int popTag()popTag restores the current document root after a call to pushTag.
pushTag( ... )
bool pushTag(const __cxx11::string &tag, int which=0)Pushing and Popping operations are used to set the current document level. Most of the methods in ofxXmlSettings are done in relationship to just the top level tags, so pushing tags is necessary to go deeper into documents. Every pushTag should be matched with a popTag after operations at that level are finished.
pushingTag pushes the given tag which is then treated as the tag as as the document root.
readDoubleAttribute( ... )
bool readDoubleAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double &outValue, int which)readIntAttribute( ... )
bool readIntAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int &valueString, int which)readStringAttribute( ... )
bool readStringAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, __cxx11::string &outValue, int which)readTag( ... )
bool readTag(const __cxx11::string &tag, int &valHandle, int which=0)removeAttribute( ... )
void removeAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int which=0)Removes the attribute from tag name at index specified by 'which'.
removeTag( ... )
void removeTag(const __cxx11::string &tag, int which=0)Removes a tag from the current level. This differs from clearing it in that the entire tag is removed, rather than just its contents being set to empty.
save( ... )
bool save(const __cxx11::string &path)saveFile( ... )
bool saveFile(const __cxx11::string &xmlFile)Saves the current state of the xml settings object to file at xmlFile path.
saveFile( )
bool saveFile()Saves the current state of the xml file to its current path. The current path is defined by whatever path was specified when loadFile(xmlFile) or saveFile(xmlFile) was last called.
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &value)Refer to addAttribute
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &value, int which=0)Refer to addAttribute
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int value)Refer to addAttribute
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double value)Refer to addAttribute
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, int value, int which=0)Returns the value of the attribute on tag as a double.
setAttribute( ... )
int setAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, double value, int which=0)Refer to addAttribute
setValue( ... )
int setValue(const __cxx11::string &tag, const __cxx11::string &value, int which=0)Sets the value of a tag to a string value. If the tag already exists, the current value is replaced with value otherwise a new tag is created.
The number of tags with the same name at the current document level is returned.
setValue( ... )
int setValue(const __cxx11::string &tag, int value, int which=0)Sets the value of a tag to an integer value. If the tag already exists, the current value is replaced with value. Otherwise a new tag is created.
The number of tags with the same name at the current document level is returned.
setValue( ... )
int setValue(const __cxx11::string &tag, double value, int which=0)Sets the value of a tag to an integer value. If the tag already exists, the current value is replaced with value otherwise a new tag is created.
The number of tags with the same name at the current document level is returned.
setVerbose( ... )
void setVerbose(bool _verbose)tagExists( ... )
bool tagExists(const __cxx11::string &tag, int which=0)Returns true if the given tag exists at the current pushTag level.
writeAttribute( ... )
int writeAttribute(const __cxx11::string &tag, const __cxx11::string &attribute, const __cxx11::string &valueString, int which=0)writeTag( ... )
int writeTag(const __cxx11::string &tag, const __cxx11::string &valueString, int which=0)~ofxXmlSettings( )
~ofxXmlSettings()