pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
NAME
pfvXmlNode - Read and write XML configuration files.
FUNCTION SPECIFICATION
#include <Performer/pfv/pfvXml.h>
pfvXmlNode::pfvXmlNode();
pfvXmlNode::pfvXmlNode(char*name);
pfvXmlNode::pfvXmlNode(char*name, char*fmt, ...);
pfvXmlNode::~pfvXmlNode();
static pfvXmlNode* pfvXmlNode::parseFile(char* filename);
char* pfvXmlNode::pfvXmlNode::getName();
void pfvXmlNode::setName(char* _name);
int pfvXmlNode::nameCmp(char* str);
int pfvXmlNode::nameCaseSensitiveCmp(char* str);
int pfvXmlNode::getNumAttr();
int pfvXmlNode::getAttr(int i, char** _name,
char** val);
char* pfvXmlNode::getAttr(char* _name);
int pfvXmlNode::setAttr(char* _name, char*val);
int pfvXmlNode::setAttr(const char ** atts);
int pfvXmlNode::findAttr(char* _name);
int pfvXmlNode::removeAttr(char* _name);
int pfvXmlNode::removeAttr(int i);
char* pfvXmlNode::getValue();
void pfvXmlNode::setValue(char* val);
char* pfvXmlNode::getString();
void pfvXmlNode::setString(char* val);
int pfvXmlNode::getBool(int* v);
Page 1
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
int pfvXmlNode::getInt(int* v);
int pfvXmlNode::getIntArray(int num, int* dst);
int pfvXmlNode::getFloat(float* f);
int pfvXmlNode::getFloatArray(int num, float* dst);
int pfvXmlNode::getDouble(double* f);
int pfvXmlNode::getDoubleArray(int num, double* dst);
int pfvXmlNode::getInputMngrKey(int* key);
int pfvXmlNode::getNotifyLevel(int* nl);
pfvXmlNode* pfvXmlNode::getParent();
int pfvXmlNode::getNumChildren();
pfvXmlNode* pfvXmlNode::getChild(int i);
pfvXmlNode* pfvXmlNode::findChild(char* _name);
int pfvXmlNode::addChild(pfvXmlNode* child);
int pfvXmlNode::addLeaf(char* _name, char* tmp, ...);
int pfvXmlNode::removeChild(pfvXmlNode* child);
int pfvXmlNode::removeChild(int i);
int pfvXmlNode::write(char* filename);
int pfvXmlNode::write(FILE*fp, int indent);
DESCRIPTION
The pfvXmlNode class allows easy parsing of XML configuration files. A
single pfvXmlNode represents the contents of a single XML tag. As XML
tags may contain other tags, pfvXmlNodes can be joined together to form a
hierarchy. The contents of an entire XML file can be parsed into a
hierarchy of pfvXmlNodes rooted by a single node. Each pfvXmlNode has a
name, an optional list of attributes, and either a string value or a list
of children nodes.
new pfvXmlNode() creates and returns a handle to a pfvXmlNode. By default
the node will have no name, no attributes, no value and no children.
new pfvXmlNode(char*name) creates a pfvXmlNode, sets its name to the
string poited to by parameter 'name', and returns a handle to it.
new pfvXmlNode(char*name, char*fmt, ...) creates a pfvXmlNode, sets its
Page 2
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
name to the string poited to by parameter 'name' and its value to the
string generated by calling vsnprintf with the provided formatted string
and variable argument list. Note that libpfv uses a static buffer to
generate this string and thus the resulting value string may be truncated
to the size of this buffer (currently 4K).
delete pfvXmlNode will delete a pfvXmlNode and all the data associated
with it, including its name, list of attributes, its value and its list
of children nodes. Note that deleting a pfvXmlNode will cause the
recursive deletion of all of its children.
pfvXmlNode::parseFile will try to open the XML file named filename, and
will parse its contents into a hierarchy of pfvXmlNode classes, returning
a pointer to the root node of the hierarchy.
pfvXmlNode::pfvXmlNode::getName returns the name of the xmlNode or NULL
if the xmlNode has no name.
pfvXmlNode::setName sets the name of the xmlNode to _name.
pfvXmlNode::nameCmp executes a case-insensitive comparison of the string
str with the name of the xmlNode. A return of 0 indicates that the two
strings match.
pfvXmlNode::nameCaseSensitiveCmp executes a case-sensitive comparison of
the string str with the name of the xmlNode. A return of 0 indicates that
the two strings match.
pfvXmlNode::getNumAttr returns the number of attributes associated with
the xmlNode. Each attribute consists of a pair of strings: its name, and
its value.
pfvXmlNode::getAttr(int i, char** _name, char** val) sets *_name and
*_val to point to the name and value of the i-th attribute of the
xmlNode.
pfvXmlNode::getAttr(char* _name) searches for the first attribute of the
xmlNode whose name matches _name and returns a pointer to its associated
value.
pfvXmlNode::setAttr(char* _name, char* val) sets the value associated
with the first attribute of xmlNode whose name matches _name to val. The
string pointed to by val is copied into memory managed by xmlNode. If no
attribute matches _name, a new attribute with name _name will be added to
xmlNode attribute-list.
pfvXmlNode::setAttr(const char **atts) allows to set multiple attributes
of xmlNode. atts points to an array of pointers to strings. Each pair of
consecutive strings is interpreted as an attribute's name and value. The
first attribute with matching name is set to the associated value. If no
attribute of xmlNode maches given name, a new attribute will be added to
Page 3
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
attribute-list. The atts array must be terminated by a NULL element.
pfvXmlNode::findAttr returns the index of the first attribute of xmlNode
whose name matches _name. If no atribute is found with matching name, -1
is returned.
pfvXmlNode::removeAttr(char* name) removes the first attribute of xmlNode
whose name matches _name. Method returns 1 if an attribute was removed, 0
otherwise.
pfvXmlNode::removeAttr(int i) removes the i-th attribute of xmlNode, if i
is a valid index. Method returns 1 if the attribute was removed, and 0
otherwise.
pfvXmlNode::getValue returns the value string associated with xmlNode.
pfvXmlNode::setValue sets the value string associated with xmlNode to the
string pointed to by val. String is copied into memory managed by
xmlNode.
pfvXmlNode::getString is an alias for pfvXmlNode::getValue.
pfvXmlNode::setString is an alias for pfvXmlNode::setValue.
pfvXmlNode::getBool parses the value string associated with xmlNode and
interprets it as a bool, setting the value of *v to 1 if string matches
"1", "yes", "y", "on", or setting *v to 0 if string matches "0", "no",
"n" or "off". Method returns 1 if a valid conversion was performed, 0
otherwise.
pfvXmlNode::getInt parses the value string associated with xmlNode and
interprets it as an integer, setting the value of *v to the converted
integer value. Method returns 1 if a valid conversion was performed, 0
otherwise.
pfvXmlNode::getIntArray parses the value string associated with xmlNode
and interprets it as an array of integers. Up to num integers separated
by commas are looked for and the corresponding converted values stored in
the array pointed to by dst. Method returns the number of successful
conversions that were carried out.
pfvXmlNode::getFloat parses the value string associated with xmlNode and
interprets it as a float, setting the value of *v to the converted
floating point value. Method returns 1 if a valid conversion was
performed, 0 otherwise.
pfvXmlNode::getFloatArray parses the value string associated with xmlNode
and interprets it as an array of floats. Up to num floats separated by
commas are looked for and the corresponding converted values stored in
the array pointed to by dst. Method returns the number of successful
conversions that were carried out.
Page 4
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
pfvXmlNode::getDouble parses the value string associated with xmlNode and
interprets it as a double, setting the value of *v to the converted
double precision floating point value. Method returns 1 if a valid
conversion was performed, 0 otherwise.
pfvXmlNode::getDoubleArray parses the value string associated with
xmlNode and interprets it as an array of doubles. Up to num double
precision floating point values separated by commas are looked for and
the corresponding converted values stored in the array pointed to by dst.
Method returns the number of successful conversions that were carried
out.
pfvXmlNode::getInputMngrKey parses the value string associated with
xmlNode and interprets it as a key, as defined in pfvinput.h. See
pfvInputMngr:getKeyFromName for a list of valid strings and their
corresponding key values. *keyName is set to the converted key value.
Method returns 1 if a valid conversion was performed, 0 otherwise.
pfvXmlNode::getNotifyLevel parses the value string associated with
xmlNode and interprets it as a notification level corresponding to those
used as arguments to function pfNotifyLevel. *nl is set to the converted
notify level value. Method returns 1 if a valid conversion was performed,
0 otherwise. The supported strings and their associated values are:
"ALWAYS" -> PFNFY_ALWAYS
"FATAL" -> PFNFY_FATAL
"WARN" -> PFNFY_WARN
"NOTICE" -> PFNFY_NOTICE
"INFO" -> PFNFY_INFO
"DEBUG" -> PFNFY_DEBUG
"FP_DEBUG" -> PFNFY_FP_DEBUG
"INTERNAL_DEBUG" -> PFNFY_INTERNAL_DEBUG
pfvXmlNode* pfvXmlNode::getParent returns a pointer to the parent node of
xmlNode, or NULL if xmlNode has no parent.
pfvXmlNode::getNumChildren returns the number of children nodes of
xmlNode.
pfvXmlNode::getChild returns a pointer to the i-th child of xmlNode, if i
is a valid index, or 0 otherwise.
pfvXmlNode::findChild returns a pointer to the first child of xmlNode
whose name matches _name, or NULL if no child of xmlNode matches _name.
pfvXmlNode::addChild adds node child to the list of children nodes of
xmlNode. If node is already a child of xmlNode, it will not be added
again.
pfvXmlNode::addLeaf creates a new xmlNode, assigns it name _name, sets
its value to the string generated by calling vsnprintf with the provided
Page 5
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
formatted string and variable argument list. Note that libpfv uses a
static buffer to generate this string and thus the resulting value string
may be truncated to the size of this buffer (currently 4K).
pfvXmlNode::removeChild(pfvXmlNode* child) removes xmlNode child from
children list of xmlnode.
pfvXmlNode::removeChild(int i) removes the i-th child node from the
children list of xmlNode.
pfvXmlNode::write(char* filename) creates an xml file containig the data
currently associated with xmlNode and all of its children. The format of
the generated file is suitable for being re-loaded with method
pfvXmlNode::parseFile.
pfvXmlNode::write(FILE*fp, int indent) appends the data currently
associated with xmlNode and all of its children to the open xml file fp.
The value of indent determines the amount of spaces prepended to each
outputed line.
NOTES
File Format Specifications:
o Files must start with the line: <?xml version="1.0" ?>
o The rest of the file must be included into a single
root-tag: <node>...</node>
o Each tag (xmlNode) starts with an opening tag containing
its name, eg: <name>, and an optional list of attributes,
eg: <name attr0="attr0-val" attr1="atr1-val">
o Attribute values must be bound by double-quotes.
o xmlNodes may either have a value (a string), or a list of
children tags
Eg:
<name attr0="attr-val0">value</name>
or
<name attr0="attr-val0" attr1="attr1-val">
<childname..>...</childname>
<child2>..</child2>
</name>
o xmlNodes end with a closing tag containing name as specified
by corresponding opening tag, eg: <color>blue</color>,
or: <color> <r>0.3</r> <g>0.5</g> <b>1.0</b> </color>
Example:
<?xml version="1.0" ?>
<rootnode>
<node0 attr0="foo">
<childNode0>value</childNode0>
<childNode1 att="xyz">string</childNode1>
Page 6
pfvXmlNode(3pf) OpenGL Performer 3.2.2 libpfv C++ Reference Pages
</node0>
<node1>val</node1>
</rootnode>
External references:
The special tag <include>filename</include> allows xml files to be
referenced from within other xml files. When referencing file is parsed,
xmlNodes with name "include" will be substituted with the xmlNodes
returned by a call to pfvXmlNode::loadFile(filename).
Example:
<?xml version="1.0" ?>
<cfg>
<include>../display-cfg/3pipe.xml</include>
<notify>WARN</notify>
</cfg>
SEE ALSO
pfvInputMngr, pfNotify, Expat
Page 7