Xml Class
As Unigine extensively uses XML for storing different types of data, it also provides functionality for parsing and saving files of this type.
See Also#
- C++ API sample <UnigineSDK>/source/samples/Api/Systems/Xml
- C# API sample <UnigineSDK>/source/csharp/samples/Api/Systems/Xml
Xml Class
Members
static Xml ( ) #
Default constructor that creates an empty instance.static Xml ( string name, string args = 0 ) #
Creates an XML tree with a given node as a root.Arguments
- string name - Name of the node that will be a root.
- string args - Optional arguments to the root node. If provided, they should be in this form:
arg1=\"value1\" arg2=\"value2\" …
If values do not contain spaces, escaped quotes can be omitted.
setArg ( ) #
Sets a literal value of a given argument.Arguments
Return value
Returns 1 if the argument is set successfully; otherwise, 0.int isArg ( string name ) #
Checks whether an argument with a given name exists.Arguments
- string name - Name to check.
Return value
1 if the argument exists; otherwise, 0.void setArgName ( int num, string name ) #
Sets the XML argument name.Arguments
- int num - The argument number.
- string name - The argument name.
string getArgName ( int num ) #
Returns argument name by its number.Arguments
- int num - Argument number.
Return value
Argument name.void setArgValue ( int num, string value ) #
Sets the XML argument value.Arguments
- int num - The argument number.
- string value - The argument value.
string getArgValue ( int num ) #
Returns the XML argument value.Arguments
- int num - The argument number.
Return value
Argument value.int setBoolArg ( string name, int value ) #
Sets a value of a given boolean argument.Arguments
- string name - Name of an argument.
- int value - Value of the argument. Any non-zero value means true, the zero value means false.
Return value
Returns 1 if the operation was successful; otherwise, 0.int getBoolArg ( string name, int value ) #
Returns a value of a given boolean argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
- int value - Default value of the argument.
Return value
1 if the argument has a value 1, true or TRUE; 0, if the argument has a value 0, false or FALSE; otherwise, 0.int getBoolArg ( string name ) #
Returns a value of a given boolean argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
1 if the argument has a value 1, true or TRUE; 0, if the argument has a value 0, false or FALSE; otherwise, 0.void setBoolData ( int data ) #
Sets a boolean content for the node. This can be done only for nodes with no children.Arguments
- int data - Content to set. Any non-zero value means true, the zero value means false.
int getBoolData ( ) #
Returns a boolean interpretation of data stored in the node.Return value
1 if a value equals to 1, true or TRUE; 0, if the value equals to 0, false or FALSE; otherwise, 0.getChild ( int num ) #
Returns a child node by its name or index number in the child list.To check, if a child with a given name exists, use the isChild() method.
Arguments
Return value
Target child node, if it is found; otherwise, 0.int isChild ( string name ) #
Checks if a child element with a given name exists.Arguments
- string name - Element name to check.
Return value
1 if a child with the provided name exists; otherwise, 0.getChildData ( variable value ) #
Gets the data from the XML child node.Arguments
- variable value - Type of the child (int, float, vec3, vec4, dvec3, dvec4, ivec3, ivec4, mat4, dmat4, quat, string).
Return value
The value of the child node.int setDMat4Arg ( string name, dmat4 value ) #
Sets a value of a given dmat4 argument.Arguments
- string name - Name of an argument.
- dmat4 value - Value of an argument.
Return value
Always 1.dmat4 getDMat4Arg ( string name ) #
Returns a value of a given dmat4 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setDMat4Data ( dmat4 data ) #
Sets a dmat4 matrix content for the node. This can be done only for nodes with no children.Arguments
- dmat4 data - Content to set.
dmat4 getDMat4Data ( ) #
Returns a dmat4 matrix interpretation of data stored in the node.Return value
Data stored in the node.int setDoubleArg ( string name, double value ) #
Sets a value of a given double argument.Arguments
- string name - Name of an argument.
- double value - Value of an argument.
Return value
Always 1.double getDoubleArg ( string name, double value ) #
Returns a value of a given double argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
- double value - Default value of the argument.
Return value
Argument value.double getDoubleArg ( string name ) #
Returns a value of a given double argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.setDoubleArrayArg ( double[] src ) #
Sets a vector of double as a value of a given argument.Arguments
- double[] src - Reference to a vector with double components.
Return value
Always 1.getDoubleArrayArg ( string name ) #
Returns a set of double values stored in an argument and puts them in a vector.Arguments
- string name - Name of a target argument.
Return value
1 if dest contains anything; otherwise, 0.setDoubleArrayData ( double[] src ) #
Sets a vector of double components as a content for the node. This can be done only for nodes with no children.Arguments
- double[] src - Reference to a vector with double components.
Return value
1 if the content is set successfully; otherwise, 0.getDoubleArrayData ( out double[] dest ) #
Returns an interpretation of data stored in the node as a vector of double components.Arguments
- out double[] dest - Reference to a vector with double components.
Return value
1 if dest contains anything; otherwise, 0.void setDoubleData ( double data ) #
Sets a double content for the node. This can be done only for nodes with no children.Arguments
- double data - Content to set.
double getDoubleData ( ) #
Returns a double interpretation of data stored in the node.Return value
Data stored in the node.int setDVec2Arg ( string name, dvec2 value ) #
Sets a value of a given dvec2 argument.Arguments
- string name - Name of an argument.
- dvec2 value - Value of an argument.
Return value
Always 1.dvec2 getDVec2Arg ( string name ) #
Returns a value of a given dvec2 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setDVec2Data ( dvec2 data ) #
Sets a dvec2 content for the node. This can be done only for nodes with no children.Arguments
- dvec2 data - Content to set.
dvec2 getDVec2Data ( ) #
Returns a dvec2 interpretation of data stored in the node.Return value
Data stored in the node.int setDVec3Arg ( string name, dvec3 value ) #
Sets a value of a given dvec3 argument.Arguments
- string name - Name of an argument.
- dvec3 value - Value of an argument.
Return value
Always 1.dvec3 getDVec3Arg ( string name ) #
Returns a value of a given dvec3 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setDVec3Data ( dvec3 data ) #
Sets a dvec3 content for the node. This can be done only for nodes with no children.Arguments
- dvec3 data - Content to set.
dvec3 getDVec3Data ( ) #
Returns a dvec3 interpretation of data stored in the node.Return value
Data stored in the node.int setDVec4Arg ( string name, dvec4 value ) #
Sets a value of a given dvec4 argument.Arguments
- string name - Name of an argument.
- dvec4 value - Value of an argument.
Return value
Always 1.dvec4 getDVec4Arg ( string name ) #
Returns a value of a given dvec4 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setDVec4Data ( dvec4 data ) #
Sets a dvec4 content for the node. This can be done only for nodes with no children.Arguments
- dvec4 data - Content to set.
dvec4 getDVec4Data ( ) #
Returns a dvec4 interpretation of data stored in the node.Return value
Data stored in the node.int setFloatArg ( string name, float value ) #
Sets a value of a given float argument.Arguments
- string name - Name of an argument.
- float value - Value of an argument.
Return value
Always 1.float getFloatArg ( string name, float value ) #
Returns a value of a given float argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
- float value - Default value of the argument.
Return value
Argument value.float getFloatArg ( string name ) #
Returns a value of a given float argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.setFloatArrayArg ( float[] src ) #
Sets a vector of floats as a value of a given argument.Arguments
- float[] src - Target vector.Reference to a vector.
Return value
Always 1.getFloatArrayArg ( out float[] dest ) #
Returns a set of float values stored in an argument and puts them in a vector.Arguments
- out float[] dest - Reference to a vector.
Return value
1 if dest contains anything; otherwise, 0.setFloatArrayData ( float[] src ) #
Sets a vector of floats as a content for the node. This can be done only for nodes with no children.Arguments
- float[] src - Reference to a vector.
Return value
1 if the content is set successfully; otherwise, 0.getFloatArrayData ( out float[] dest ) #
Returns an interpretation of data stored in the node as a vector of floats.Arguments
- out float[] dest - Reference to a vector.
Return value
1 if dest contains anything; otherwise, 0.void setFloatData ( float data ) #
Sets a float content for the node. This can be done only for nodes with no children.Arguments
- float data - Content to set.
float getFloatData ( ) #
Returns a float interpretation of data stored in the node.Return value
Data stored in the node.getFormattedSubTree ( ) #
Converts the specified XML subtree into a formatted string for "pretty printing". If no arguments are passed, the entire XML tree is converted.Arguments
Return value
Multi-line indented output of the specified XML subtree.int setIntArg ( string name, int value, int radix = 10 ) #
Sets a value for a given int argument in a given number notation. By default, the decimal number notation is used.Arguments
- string name - Name of an argument.
- int value - Value of an argument.
- int radix - Radix to use when setting a value.
Return value
1 if the value is set successfully; otherwise, 0.int getIntArg ( string name ) #
Returns a value of a given int argument.To check whether the argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.int getIntArg ( string name, int value ) #
Returns a value of a given int argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
- int value - Default value of the argument.
Return value
Argument value.setIntArrayArg ( int[] src, int radix = 10 ) #
Sets an array of integers as xml argument in a given number notation. By default, the decimal number notation is used.Arguments
- int[] src - Reference to a vector.
- int radix - Radix to use when setting a value.
Return value
1 if the array is set successfully; otherwise, 0.setIntArrayData ( int[] src, int radix ) #
Sets a vector of integers as a content for the XML node in a given number notation. By default, the decimal number notation is used. This can be done only for XML nodes with no children.Arguments
- int[] src - Reference to a vector.
- int radix - Radix to use when setting a value.
Return value
1 if the content is set successfully; otherwise, 0.getIntArrayData ( out int[] dest ) #
Returns an interpretation of data stored in the node as a vector of integers.Arguments
- out int[] dest - Reference to a vector.
Return value
1 if values are read successfully; otherwise, 0.int setIntData ( int value, int radix = 10 ) #
Sets an integer as a content for the XML node in a given number notation. By default, the decimal number notation is used. This can be done only for XML nodes with no children.Arguments
- int value - Content to set.
- int radix - Radix to use when setting a value.
Return value
1 if the content is set successfully; otherwise, 0.int getIntData ( ) #
Returns an integer interpretation of data stored in the node.Return value
Data stored in the node.int setIVec2Arg ( string name, ivec2 value ) #
Sets a value of a given ivec2 argument.Arguments
- string name - Name of an argument.
- ivec2 value - Value of an argument.
Return value
Always 1.ivec2 getIVec2Arg ( string name ) #
Returns a value of a given ivec2 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setIVec2Data ( ivec2 data ) #
Sets a ivec2 content for the node. This can be done only for nodes with no children.Arguments
- ivec2 data - Content to set.
ivec2 getIVec2Data ( ) #
Returns a ivec2 interpretation of data stored in the node.Return value
Data stored in the node.int setIVec3Arg ( string name, ivec3 value ) #
Sets a value of a given ivec3 argument.Arguments
- string name - Name of an argument.
- ivec3 value - Value of an argument.
Return value
Always 1.ivec3 getIVec3Arg ( string name ) #
Returns a value of a given ivec3 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setIVec3Data ( ivec3 data ) #
Sets a ivec3 content for the node. This can be done only for nodes with no children.Arguments
- ivec3 data - Content to set.
ivec3 getIVec3Data ( ) #
Returns a ivec3 interpretation of data stored in the node.Return value
Data stored in the node.int setIVec4Arg ( string name, ivec4 value ) #
Sets a value of a given ivec4 argument.Arguments
- string name - Name of an argument.
- ivec4 value - Value of an argument.
Return value
Always 1.ivec4 getIVec4Arg ( string name ) #
Returns a value of a given ivec4 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setIVec4Data ( ivec4 data ) #
Sets a ivec4 content for the node. This can be done only for nodes with no children.Arguments
- ivec4 data - Content to set.
ivec4 getIVec4Data ( ) #
Returns a ivec4 interpretation of data stored in the node.Return value
Data stored in the node.void setLongData ( long data ) #
Sets a long content for the node. This can be done only for nodes with no children.Arguments
- long data - Content to be set.
long getLongData ( ) #
Returns a long interpretation of data stored in the node.Return value
Data stored in the node.int setMat4Arg ( string name, mat4 value ) #
Sets a value of a given mat4 argument.Arguments
- string name - Name of an argument.
- mat4 value - Value of an argument.
Return value
Always 1.mat4 getMat4Arg ( string name ) #
Returns a value of a given mat4 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setMat4Data ( mat4 data ) #
Sets a mat4 matrix content for the node. This can be done only for nodes with no children.Arguments
- mat4 data - Content to set.
mat4 getMat4Data ( ) #
Returns a mat4 matrix interpretation of data stored in the node.Return value
Data stored in the node.void setName ( string name ) #
Sets a name of the node.Arguments
- string name - Node name.
string getName ( ) #
Returns a name of the node.Return value
Node name.int getNumArgs ( ) #
Returns a number of arguments.Return value
Number of arguments.int getNumChildren ( ) #
Returns a number of children contained in the node.In the standard XML model the child nodes can be of the following types: node, text node and comment. The data of the XML node is considered to be an unnamed child node, resulting in correct parsing of such a code:
<text>
text</br>text
</text>
Return value
Number of children.int setQuatArg ( string name, quat value ) #
Sets a value of a given quat argument.Arguments
- string name - Name of an argument.
- quat value - Value of an argument.
Return value
Always 1.quat getQuatArg ( string name ) #
Returns a value of a given quat argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setQuatData ( quat data ) #
Sets a quaternion content for the node. This can be done only for nodes with no children.Arguments
- quat data - Content to set.
quat getQuatData ( ) #
Returns a quaternion interpretation of data stored in the node.Return value
Data stored in the node.int setRawData ( string data ) #
Sets a raw content for the node. Raw data will be automatically formatted as a CDATA section. This can be done only for nodes with no children.Arguments
- string data - Content to set.
Return value
1 if the content is set successfully; otherwise, 0.setStringArrayArg ( ) #
Sets a vector of strings as a value of a given argument in a given number notation. By default, the decimal number notation is used.Arguments
Return value
Always 1.getStringArrayArg ( ) #
Returns a set of string values stored in an argument and puts them in a vector.Arguments
Return value
1 if dest contains anything; otherwise, 0.String getSubTree ( string path = 0 ) #
Dumps the node tree.Arguments
- string path - Path to the node. See the description of find() for more details.
Return value
Single-line non-indented output of the node tree. If no arguments are passed, the entire XML tree would be output.int setVec2Arg ( string name, vec2 value ) #
Sets a value of a given vec2 argument.Arguments
- string name - Name of an argument.
- vec2 value - Value of an argument.
Return value
Always 1.vec2 getVec2Arg ( string name ) #
Returns a value of a given vec2 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setVec2Data ( vec2 data ) #
Sets a vec2 content for the node. This can be done only for nodes with no children.Arguments
- vec2 data - Content to set.
vec2 getVec2Data ( ) #
Returns a vec2 interpretation of data stored in the node.Return value
Data stored in the node.int setVec3Arg ( string name, vec3 value ) #
Sets a value of a given vec3 argument.Arguments
- string name - Name of an argument.
- vec3 value - Value of an argument.
Return value
Always 1.vec3 getVec3Arg ( string name ) #
Returns a value of a given vec3 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setVec3Data ( vec3 data ) #
Sets a vec3 content for the node. This can be done only for nodes with no children.Arguments
- vec3 data - Content to set.
vec3 getVec3Data ( ) #
Returns a vec3 interpretation of data stored in the node.Return value
Data stored in the node.int setVec4Arg ( string name, vec4 value ) #
Sets a value of a given vec4 argument.Arguments
- string name - Name of an argument.
- vec4 value - Value of an argument.
Return value
Always 1.vec4 getVec4Arg ( string name ) #
Returns a value of a given vec4 argument.To check, if an argument exists, use the isArg() method.
Arguments
- string name - Name of a target argument.
Return value
Argument value.void setVec4Data ( vec4 data ) #
Sets a vec4 content for the node. This can be done only for nodes with no children.Arguments
- vec4 data - Content to set.
vec4 getVec4Data ( ) #
Returns a vec4 interpretation of data stored in the node.Return value
Data stored in the node.int setXmlData ( string data ) #
Sets an unquoted string to data stored in the node. This string can also contain XML sub-tree with rich text formating.Arguments
- string data - Unquoted string to set.
Return value
1 if the string is set successfully; otherwise, 0.addChild ( ) #
Appends a new XML node to the current XML node as a child.Arguments
Return value
Created XML node.Xml addChild ( Xml xml ) #
Appends a new XML node to the current XML node as a child.Arguments
- Xml xml - Argument of one of the following types:
- Xml xml - XML node.
- string name - Name of the XML node.
Return value
Created XML node.void clear ( ) #
Clears all data associated with the node.void clearChildren ( ) #
Clears all children of the current XML node.void clearUnusedData ( ) #
Clears the unused nodes and arguments.void copy ( Xml source ) #
Copies all data (name, arguments, data, flags and a child hierarchy) from the source XML node to the current one.Arguments
- Xml source - Source XML node.
String decode ( string arg1 ) #
Decodes special XML characters (less-than, greater-than, ampersand, double-quote and apostrophe) and numeric character references.Arguments
- string arg1 - Data to decode.
Return value
Decoded string.String encode ( string arg1 ) #
Encodes special XML characters (less-than, greater-than, ampersand, double-quote and apostrophe) to their character entity reference.Arguments
- string arg1 - Data to encode.
Return value
Encoded string.int findArg ( string name ) #
Searches for a XML argument by its name.Arguments
- string name - XML argument name.
Return value
XML argument number.int findChild ( string name ) #
Searches for the number of the XML node child by name.Arguments
- string name - Name of the XML node child.
Return value
The number of the XML node child if it is exists; otherwise, -1.int load ( string name ) #
Loads an XML document and sets the current node to be the root of the parsed tree.Arguments
- string name - File name.
Return value
1 if the file is read and parsed successfully; otherwise, 0.int parse ( string src ) #
Parses a string with XML mark-up and sets the current node to be the root of the parsed tree.Arguments
- string src - String with an XML content.
Return value
1 if a string is successfully parsed; otherwise 0.void printUnusedData ( string name ) #
Logs warnings of unused data for debugging.Arguments
- string name - Path to the file.
int removeArg ( string name ) #
Removes the argument with the given name from the list of the current XML node arguments.Arguments
- string name - Name of the target argument.
Return value
1 if the argument is deleted successfully; otherwise, 0.removeChild ( ) #
Removes a child node and its descendants from the current XML node.Arguments
Return value
Removed child node and its descendants, if they are found; otherwise, 0.save ( ) #
Formats the tree of the current node and writes is to the specified file in the specified format.Arguments
Return value
1 if the file is written successfully; otherwise, 0.String symbols ( string arg1 ) #
Replaces ampersand characters with character entity references.Arguments
- string arg1 - String to encode.
Return value
String which contains replaced ampersand characters with character entity references.void setIntData ( int data ) #
Arguments
- int data
Last update:
2019-08-16
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)