Rebel Fork Framework
Urho3D::XMLElement Class Reference

Element in an XML file. More...

#include <Urho3D/Resource/XMLElement.h>

Public Member Functions

 XMLElement ()
 Construct null element.
 
 XMLElement (const XMLFile *file, pugi::xml_node_struct *node)
 Construct with document and node pointers.
 
 XMLElement (const XMLFile *file, const XPathResultSet *resultSet, const pugi::xpath_node *xpathNode, unsigned xpathResultIndex)
 Construct from xpath query result set.
 
 XMLElement (const XMLElement &rhs)
 Copy-construct from another element.
 
 ~XMLElement ()
 Destruct.
 
XMLElementoperator= (const XMLElement &rhs)
 Assignment operator.
 
void SetName (const ea::string &name)
 Set element name.
 
void SetName (const char *name)
 Set element name.
 
XMLElement CreateChild (const ea::string &name)
 Create a child element.
 
XMLElement CreateChild (const char *name)
 Create a child element.
 
XMLElement GetOrCreateChild (const ea::string &name)
 Return the first child element with name or create if does not exist.
 
XMLElement GetOrCreateChild (const char *name)
 Return the first child element with name or create if does not exist.
 
bool AppendChild (XMLElement element, bool asCopy=false)
 Append element. If asCopy is set to true then original element is copied and appended, otherwise specified element is appended.
 
bool Remove ()
 Remove element from its parent.
 
bool RemoveChild (const XMLElement &element)
 Remove a child element. Return true if successful.
 
bool RemoveChild (const ea::string &name)
 Remove a child element by name. Return true if successful.
 
bool RemoveChild (const char *name)
 Remove a child element by name. Return true if successful.
 
bool RemoveChildren (const ea::string &name=EMPTY_STRING)
 Remove child elements of certain name, or all child elements if name is empty. Return true if successful.
 
bool RemoveChildren (const char *name)
 Remove child elements of certain name, or all child elements if name is empty. Return true if successful.
 
bool RemoveAttribute (const ea::string &name=EMPTY_STRING)
 Remove an attribute by name. Return true if successful.
 
bool RemoveAttribute (const char *name)
 Remove an attribute by name. Return true if successful.
 
XMLElement SelectSingle (const ea::string &query, pugi::xpath_variable_set *variables=nullptr) const
 Select an element/attribute using XPath query.
 
XMLElement SelectSinglePrepared (const XPathQuery &query) const
 Select an element/attribute using XPath query.
 
XPathResultSet Select (const ea::string &query, pugi::xpath_variable_set *variables=nullptr) const
 Select elements/attributes using XPath query.
 
XPathResultSet SelectPrepared (const XPathQuery &query) const
 Select elements/attributes using XPath query.
 
bool SetValue (const ea::string &value)
 
bool SetValue (const char *value)
 Set the value for an inner node in the following format <node>value</node>. Must be used on the <node> element.
 
bool SetAttribute (const ea::string &name, const ea::string &value)
 Set an attribute.
 
bool SetAttribute (const char *name, const char *value)
 Set an attribute.
 
bool SetAttribute (const ea::string &value)
 Set an attribute. Only valid if it is an attribute only XPath query result.
 
bool SetAttribute (const char *value)
 Set an attribute. Only valid if it is an attribute only XPath query result.
 
bool SetBool (const ea::string &name, bool value)
 Set a bool attribute.
 
bool SetBoundingBox (const BoundingBox &value)
 Set a BoundingBox attribute.
 
bool SetBuffer (const ea::string &name, const void *data, unsigned size)
 Set a buffer attribute.
 
bool SetBuffer (const ea::string &name, const ea::vector< unsigned char > &value)
 Set a buffer attribute.
 
bool SetColor (const ea::string &name, const Color &value)
 Set a color attribute.
 
bool SetFloat (const ea::string &name, float value)
 Set a float attribute.
 
bool SetDouble (const ea::string &name, double value)
 Set a double attribute.
 
bool SetUInt (const ea::string &name, unsigned value)
 Set an unsigned integer attribute.
 
bool SetInt (const ea::string &name, int value)
 Set an integer attribute.
 
bool SetUInt64 (const ea::string &name, unsigned long long value)
 Set an unsigned long long integer attribute.
 
bool SetInt64 (const ea::string &name, long long value)
 Set a long long integer attribute.
 
bool SetIntRect (const ea::string &name, const IntRect &value)
 Set an IntRect attribute.
 
bool SetIntVector2 (const ea::string &name, const IntVector2 &value)
 Set an IntVector2 attribute.
 
bool SetIntVector3 (const ea::string &name, const IntVector3 &value)
 Set an IntVector3 attribute.
 
bool SetRect (const ea::string &name, const Rect &value)
 Set a Rect attribute.
 
bool SetQuaternion (const ea::string &name, const Quaternion &value)
 Set a quaternion attribute.
 
bool SetString (const ea::string &name, const ea::string &value)
 Set a string attribute.
 
bool SetVariant (const Variant &value)
 Set a variant attribute.
 
bool SetVariantValue (const Variant &value)
 Set a variant attribute excluding the type.
 
bool SetResourceRef (const ResourceRef &value)
 Set a resource reference attribute.
 
bool SetResourceRefList (const ResourceRefList &value)
 Set a resource reference list attribute.
 
bool SetVariantVector (const VariantVector &value)
 Set a variant vector attribute. Creates child elements as necessary.
 
bool SetStringVector (const StringVector &value)
 Set a string vector attribute. Creates child elements as necessary.
 
bool SetVariantMap (const VariantMap &value)
 Set a variant map attribute. Creates child elements as necessary.
 
bool SetStringVariantMap (const StringVariantMap &value)
 Set a string variant map attribute. Creates child elements as necessary.
 
bool SetVector2 (const ea::string &name, const Vector2 &value)
 Set a Vector2 attribute.
 
bool SetVector3 (const ea::string &name, const Vector3 &value)
 Set a Vector3 attribute.
 
bool SetVector4 (const ea::string &name, const Vector4 &value)
 Set a Vector4 attribute.
 
bool SetVectorVariant (const ea::string &name, const Variant &value)
 Set a float, Vector or Matrix attribute stored in a variant.
 
bool SetMatrix3 (const ea::string &name, const Matrix3 &value)
 Set a Matrix3 attribute.
 
bool SetMatrix3x4 (const ea::string &name, const Matrix3x4 &value)
 Set a Matrix3x4 attribute.
 
bool SetMatrix4 (const ea::string &name, const Matrix4 &value)
 Set a Matrix4 attribute.
 
bool IsNull () const
 
bool NotNull () const
 
 operator bool () const
 Return true if refers to an element or an XPath node.
 
ea::string GetName () const
 
bool HasChild (const ea::string &name) const
 Return whether has a child element.
 
bool HasChild (const char *name) const
 Return whether has a child element.
 
XMLElement GetChild (const ea::string &name=EMPTY_STRING) const
 Return child element, or null if missing.
 
XMLElement GetChild (const char *name) const
 Return child element, or null if missing.
 
XMLElement GetNext (const ea::string &name=EMPTY_STRING) const
 Return next sibling element.
 
XMLElement GetNext (const char *name) const
 Return next sibling element.
 
XMLElement GetParent () const
 
unsigned GetNumAttributes () const
 
bool HasAttribute (const ea::string &name) const
 Return whether has an attribute.
 
bool HasAttribute (const char *name) const
 Return whether has an attribute.
 
ea::string GetValue () const
 
ea::string GetAttribute (const ea::string &name=EMPTY_STRING) const
 Return attribute, or empty if missing.
 
ea::string GetAttribute (const char *name) const
 Return attribute, or empty if missing.
 
const char * GetAttributeCString (const char *name) const
 Return attribute as C string, or null if missing.
 
ea::string GetAttributeLower (const ea::string &name) const
 Return attribute in lowercase, or empty if missing.
 
ea::string GetAttributeLower (const char *name) const
 Return attribute in lowercase, or empty if missing.
 
ea::string GetAttributeUpper (const ea::string &name) const
 Return attribute in lowercase, or empty if missing.
 
ea::string GetAttributeUpper (const char *name) const
 Return attribute in lowercase, or empty if missing.
 
ea::vector< ea::string > GetAttributeNames () const
 Return names of all attributes.
 
bool GetBool (const ea::string &name) const
 Return bool attribute, or false if missing.
 
ea::vector< unsigned char > GetBuffer (const ea::string &name) const
 Return buffer attribute, or empty if missing.
 
bool GetBuffer (const ea::string &name, void *dest, unsigned size) const
 Copy buffer attribute into a supplied buffer. Return true if buffer was large enough.
 
BoundingBox GetBoundingBox () const
 Return bounding box attribute, or empty if missing.
 
Color GetColor (const ea::string &name) const
 Return a color attribute, or default if missing.
 
float GetFloat (const ea::string &name) const
 Return a float attribute, or zero if missing.
 
double GetDouble (const ea::string &name) const
 Return a double attribute, or zero if missing.
 
unsigned GetUInt (const ea::string &name) const
 Return an unsigned integer attribute, or zero if missing.
 
int GetInt (const ea::string &name) const
 Return an integer attribute, or zero if missing.
 
unsigned long long GetUInt64 (const ea::string &name) const
 Return an unsigned long long integer attribute, or zero if missing.
 
long long GetInt64 (const ea::string &name) const
 Return a long long integer attribute, or zero if missing.
 
IntRect GetIntRect (const ea::string &name) const
 Return an IntRect attribute, or default if missing.
 
IntVector2 GetIntVector2 (const ea::string &name) const
 Return an IntVector2 attribute, or default if missing.
 
IntVector3 GetIntVector3 (const ea::string &name) const
 Return an IntVector3 attribute, or default if missing.
 
Rect GetRect (const ea::string &name) const
 Return a Rect attribute, or default if missing.
 
Quaternion GetQuaternion (const ea::string &name) const
 Return a quaternion attribute, or default if missing.
 
Variant GetVariant () const
 Return a variant attribute, or empty if missing.
 
Variant GetVariantValue (VariantType type, Context *context=nullptr) const
 Return a variant attribute with static type. Context must be provided for loading SharedPtr<Serializable>.
 
ResourceRef GetResourceRef () const
 Return a resource reference attribute, or empty if missing.
 
ResourceRefList GetResourceRefList () const
 Return a resource reference list attribute, or empty if missing.
 
VariantVector GetVariantVector () const
 Return a variant vector attribute, or empty if missing.
 
StringVector GetStringVector () const
 Return a string vector attribute, or empty if missing.
 
VariantMap GetVariantMap () const
 Return a variant map attribute, or empty if missing.
 
StringVariantMap GetStringVariantMap () const
 Return a string variant map attribute, or empty if missing.
 
Vector2 GetVector2 (const ea::string &name) const
 Return a Vector2 attribute, or zero vector if missing.
 
Vector3 GetVector3 (const ea::string &name) const
 Return a Vector3 attribute, or zero vector if missing.
 
Vector4 GetVector4 (const ea::string &name) const
 Return a Vector4 attribute, or zero vector if missing.
 
Vector4 GetVector (const ea::string &name) const
 Return any Vector attribute as Vector4. Missing coordinates will be zero.
 
Variant GetVectorVariant (const ea::string &name) const
 Return a float, Vector or Matrix attribute as Variant.
 
Matrix3 GetMatrix3 (const ea::string &name) const
 Return a Matrix3 attribute, or zero matrix if missing.
 
Matrix3x4 GetMatrix3x4 (const ea::string &name) const
 Return a Matrix3x4 attribute, or zero matrix if missing.
 
Matrix4 GetMatrix4 (const ea::string &name) const
 Return a Matrix4 attribute, or zero matrix if missing.
 
const XMLFileGetFile () const
 
pugi::xml_node_struct * GetNode () const
 Return pugixml xml_node_struct.
 
const XPathResultSetGetXPathResultSet () const
 Return XPath query result set.
 
const pugi::xpath_node * GetXPathNode () const
 Return pugixml xpath_node.
 
unsigned GetXPathResultIndex () const
 Return current result index.
 
XMLElement NextResult () const
 

Static Public Attributes

static const XMLElement EMPTY
 Empty XMLElement.
 

Private Attributes

WeakPtr< const XMLFilefile_
 XML file.
 
pugi::xml_node_struct * node_
 Pugixml node.
 
const XPathResultSetxpathResultSet_
 XPath query result set.
 
const pugi::xpath_node * xpathNode_
 Pugixml xpath_node.
 
unsigned xpathResultIndex_
 Current XPath query result index (used internally to advance to subsequent query result).
 

Detailed Description

Element in an XML file.

Member Function Documentation

◆ GetFile()

const XMLFile * Urho3D::XMLElement::GetFile ( ) const

Return XML file.

◆ GetName()

ea::string Urho3D::XMLElement::GetName ( ) const

Return element name (or attribute name if it is an attribute only XPath query result).

◆ GetNumAttributes()

unsigned Urho3D::XMLElement::GetNumAttributes ( ) const

Return number of attributes.

◆ GetParent()

XMLElement Urho3D::XMLElement::GetParent ( ) const

Return parent element.

◆ GetValue()

ea::string Urho3D::XMLElement::GetValue ( ) const

Return inner value, or empty if missing for nodes like <node>value</node>.

◆ IsNull()

bool Urho3D::XMLElement::IsNull ( ) const

Return whether does not refer to an element or an XPath node.

◆ NextResult()

XMLElement Urho3D::XMLElement::NextResult ( ) const

Return next XPath query result. Only valid when this instance of XMLElement is itself one of the query result in the result set.

◆ NotNull()

bool Urho3D::XMLElement::NotNull ( ) const

Return whether refers to an element or an XPath node.

◆ SetValue()

bool Urho3D::XMLElement::SetValue ( const ea::string &  value)

Set the value for an inner node in the following format <node>value</node>.


The documentation for this class was generated from the following files: