YAGE  v0.1.1
Yet Another Game Engine
rapidxml::xml_document< Ch > Class Template Reference

This class represents root of the DOM hierarchy. It is also an xml_node and a memory_pool through public inheritance. Use parse() function to build a DOM tree from a zero-terminated XML text string. parse() function allocates memory for nodes and attributes by using functions of xml_document, which are inherited from memory_pool. To access root node of the document, use the document itself, as if it was an xml_node. More...

#include <rapidxml.h>

Inheritance diagram for rapidxml::xml_document< Ch >:
rapidxml::xml_node< Ch > rapidxml::memory_pool< Ch > rapidxml::xml_base< Ch >

Classes

struct  attribute_name_pred
 
struct  attribute_value_pred
 
struct  attribute_value_pure_pred
 
struct  node_name_pred
 
struct  text_pred
 
struct  text_pure_no_ws_pred
 
struct  text_pure_with_ws_pred
 
struct  whitespace_pred
 

Public Member Functions

 xml_document ()
 Constructs empty XML document. More...
 
template<int Flags>
void parse (Ch *text)
 Parses zero-terminated XML string according to given flags. Passed string will be modified by the parser, unless rapidxml::parse_non_destructive flag is used. The string must persist for the lifetime of the document. In case of error, rapidxml::parse_error exception will be thrown.

If you want to parse contents of a file, you must first load the file into the memory, and pass pointer to its beginning. Make sure that data is zero-terminated.

Document can be parsed into multiple times. Each new call to parse removes previous nodes and attributes (if any), but does not clear memory pool. More...
 
void clear ()
 Clears the document by deleting all nodes and clearing the memory pool. All nodes owned by document pool are destroyed. More...
 
- Public Member Functions inherited from rapidxml::xml_node< Ch >
 xml_node (node_type type)
 Constructs an empty node with the specified type. Consider using memory_pool of appropriate document to allocate nodes manually. More...
 
node_type type () const
 Gets type of node. More...
 
xml_document< Ch > * document () const
 Gets document of which node is a child. More...
 
xml_node< Ch > * first_node (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets first child node, optionally matching node name. More...
 
xml_node< Ch > * last_node (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets last child node, optionally matching node name. Behaviour is undefined if node has no children. Use first_node() to test if node has children. More...
 
xml_node< Ch > * previous_sibling (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets previous sibling node, optionally matching node name. Behaviour is undefined if node has no parent. Use parent() to test if node has a parent. More...
 
xml_node< Ch > * next_sibling (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets next sibling node, optionally matching node name. Behaviour is undefined if node has no parent. Use parent() to test if node has a parent. More...
 
xml_attribute< Ch > * first_attribute (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets first attribute of node, optionally matching attribute name. More...
 
xml_attribute< Ch > * last_attribute (const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
 Gets last attribute of node, optionally matching attribute name. More...
 
void type (node_type type)
 Sets type of node. More...
 
void prepend_node (xml_node< Ch > *child)
 Prepends a new child node. The prepended child becomes the first child, and all existing children are moved one position back. More...
 
void append_node (xml_node< Ch > *child)
 Appends a new child node. The appended child becomes the last child. More...
 
void insert_node (xml_node< Ch > *where, xml_node< Ch > *child)
 Inserts a new child node at specified place inside the node. All children after and including the specified node are moved one position back. More...
 
void remove_first_node ()
 Removes first child node. If node has no children, behaviour is undefined. Use first_node() to test if node has children. More...
 
void remove_last_node ()
 Removes last child of the node. If node has no children, behaviour is undefined. Use first_node() to test if node has children. More...
 
void remove_node (xml_node< Ch > *where)
 Removes specified child from the node. More...
 
void remove_all_nodes ()
 Removes all child nodes (but not attributes). More...
 
void prepend_attribute (xml_attribute< Ch > *attribute)
 Prepends a new attribute to the node. More...
 
void append_attribute (xml_attribute< Ch > *attribute)
 Appends a new attribute to the node. More...
 
void insert_attribute (xml_attribute< Ch > *where, xml_attribute< Ch > *attribute)
 Inserts a new attribute at specified place inside the node. All attributes after and including the specified attribute are moved one position back. More...
 
void remove_first_attribute ()
 Removes first attribute of the node. If node has no attributes, behaviour is undefined. Use first_attribute() to test if node has attributes. More...
 
void remove_last_attribute ()
 Removes last attribute of the node. If node has no attributes, behaviour is undefined. Use first_attribute() to test if node has attributes. More...
 
void remove_attribute (xml_attribute< Ch > *where)
 Removes specified attribute from node. More...
 
void remove_all_attributes ()
 Removes all attributes of node. More...
 
- Public Member Functions inherited from rapidxml::xml_base< Ch >
 xml_base ()
 
Ch * name () const
 Gets name of the node. Interpretation of name depends on type of node. Note that name will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.

Use name_size() function to determine length of the name. More...
 
std::size_t name_size () const
 Gets size of node name, not including terminator character. This function works correctly irrespective of whether name is or is not zero terminated. More...
 
Ch * value () const
 Gets value of node. Interpretation of value depends on type of node. Note that value will not be zero-terminated if rapidxml::parse_no_string_terminators option was selected during parse.

Use value_size() function to determine length of the value. More...
 
std::size_t value_size () const
 Gets size of node value, not including terminator character. This function works correctly irrespective of whether value is or is not zero terminated. More...
 
void name (const Ch *name, std::size_t size)
 Sets name of node to a non zero-terminated string. See ownership_of_strings.

Note that node does not own its name or value, it only stores a pointer to it. It will not delete or otherwise free the pointer on destruction. It is reponsibility of the user to properly manage lifetime of the string. The easiest way to achieve it is to use memory_pool of the document to allocate the string - on destruction of the document the string will be automatically freed.

Size of name must be specified separately, because name does not have to be zero terminated. Use name(const Ch *) function to have the length automatically calculated (string must be zero terminated). More...
 
void name (const Ch *name)
 Sets name of node to a zero-terminated string. See also ownership_of_strings and xml_node::name(const Ch *, std::size_t). More...
 
void value (const Ch *value, std::size_t size)
 Sets value of node to a non zero-terminated string. See ownership_of_strings.

Note that node does not own its name or value, it only stores a pointer to it. It will not delete or otherwise free the pointer on destruction. It is reponsibility of the user to properly manage lifetime of the string. The easiest way to achieve it is to use memory_pool of the document to allocate the string - on destruction of the document the string will be automatically freed.

Size of value must be specified separately, because it does not have to be zero terminated. Use value(const Ch *) function to have the length automatically calculated (string must be zero terminated).

If an element has a child node of type node_data, it will take precedence over element value when printing. If you want to manipulate data of elements using values, use parser flag rapidxml::parse_no_data_nodes to prevent creation of data nodes by the parser. More...
 
void value (const Ch *value)
 Sets value of node to a zero-terminated string. See also ownership_of_strings and xml_node::value(const Ch *, std::size_t). More...
 
xml_node< Ch > * parent () const
 Gets node parent. More...
 
- Public Member Functions inherited from rapidxml::memory_pool< Ch >
 memory_pool ()
 Constructs empty pool with default allocator functions. More...
 
 ~memory_pool ()
 Destroys pool and frees all the memory. This causes memory occupied by nodes allocated by the pool to be freed. Nodes allocated from the pool are no longer valid. More...
 
xml_node< Ch > * allocate_node (node_type type, const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0)
 Allocates a new node from the pool, and optionally assigns name and value to it. If the allocation request cannot be accomodated, this function will throw std::bad_alloc. If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function will call rapidxml::parse_error_handler() function. More...
 
xml_attribute< Ch > * allocate_attribute (const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0)
 Allocates a new attribute from the pool, and optionally assigns name and value to it. If the allocation request cannot be accomodated, this function will throw std::bad_alloc. If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function will call rapidxml::parse_error_handler() function. More...
 
Ch * allocate_string (const Ch *source=0, std::size_t size=0)
 Allocates a char array of given size from the pool, and optionally copies a given string to it. If the allocation request cannot be accomodated, this function will throw std::bad_alloc. If exceptions are disabled by defining RAPIDXML_NO_EXCEPTIONS, this function will call rapidxml::parse_error_handler() function. More...
 
xml_node< Ch > * clone_node (const xml_node< Ch > *source, xml_node< Ch > *result=0)
 Clones an xml_node and its hierarchy of child nodes and attributes. Nodes and attributes are allocated from this memory pool. Names and values are not cloned, they are shared between the clone and the source. Result node can be optionally specified as a second parameter, in which case its contents will be replaced with cloned source node. This is useful when you want to clone entire document. More...
 
void clear ()
 Clears the pool. This causes memory occupied by nodes allocated by the pool to be freed. Any nodes or strings allocated from the pool will no longer be valid. More...
 
void set_allocator (alloc_func *af, free_func *ff)
 Sets or resets the user-defined memory allocation functions for the pool. This can only be called when no memory is allocated from the pool yet, otherwise results are undefined. Allocation function must not return invalid pointer on failure. It should either throw, stop the program, or use longjmp() function to pass control to other place of program. If it returns invalid pointer, results are undefined.

User defined allocation functions must have the following forms:

void *allocate(std::size_t size);
void free(void *pointer);

More...
 

Private Member Functions

template<int Flags>
void parse_bom (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_xml_declaration (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_comment (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_doctype (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_pi (Ch *&text)
 
template<int Flags>
Ch parse_and_append_data (xml_node< Ch > *node, Ch *&text, Ch *contents_start)
 
template<int Flags>
xml_node< Ch > * parse_cdata (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_element (Ch *&text)
 
template<int Flags>
xml_node< Ch > * parse_node (Ch *&text)
 
template<int Flags>
void parse_node_contents (Ch *&text, xml_node< Ch > *node)
 
template<int Flags>
void parse_node_attributes (Ch *&text, xml_node< Ch > *node)
 

Static Private Member Functions

template<int Flags>
static void insert_coded_character (Ch *&text, unsigned long code)
 
template<class StopPred , int Flags>
static void skip (Ch *&text)
 
template<class StopPred , class StopPredPure , int Flags>
static Ch * skip_and_expand_character_refs (Ch *&text)
 

Additional Inherited Members

- Static Protected Member Functions inherited from rapidxml::xml_base< Ch >
static Ch * nullstr ()
 
- Protected Attributes inherited from rapidxml::xml_base< Ch >
Ch * m_name
 
Ch * m_value
 
std::size_t m_name_size
 
std::size_t m_value_size
 
xml_node< Ch > * m_parent
 

Detailed Description

template<class Ch = char>
class rapidxml::xml_document< Ch >

Parameters
ChCharacter type to use.

Constructor & Destructor Documentation

◆ xml_document()

template<class Ch = char>
rapidxml::xml_document< Ch >::xml_document ( )
inline

Member Function Documentation

◆ clear()

template<class Ch = char>
void rapidxml::xml_document< Ch >::clear ( )
inline

◆ insert_coded_character()

template<class Ch = char>
template<int Flags>
static void rapidxml::xml_document< Ch >::insert_coded_character ( Ch *&  text,
unsigned long  code 
)
inlinestaticprivate

◆ parse()

template<class Ch = char>
template<int Flags>
void rapidxml::xml_document< Ch >::parse ( Ch *  text)
inline
Parameters
textXML data to parse; pointer is non-const to denote fact that this data may be modified by the parser.

◆ parse_and_append_data()

template<class Ch = char>
template<int Flags>
Ch rapidxml::xml_document< Ch >::parse_and_append_data ( xml_node< Ch > *  node,
Ch *&  text,
Ch *  contents_start 
)
inlineprivate

◆ parse_bom()

template<class Ch = char>
template<int Flags>
void rapidxml::xml_document< Ch >::parse_bom ( Ch *&  text)
inlineprivate

◆ parse_cdata()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_cdata ( Ch *&  text)
inlineprivate

◆ parse_comment()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_comment ( Ch *&  text)
inlineprivate

◆ parse_doctype()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_doctype ( Ch *&  text)
inlineprivate

◆ parse_element()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_element ( Ch *&  text)
inlineprivate

◆ parse_node()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_node ( Ch *&  text)
inlineprivate

◆ parse_node_attributes()

template<class Ch = char>
template<int Flags>
void rapidxml::xml_document< Ch >::parse_node_attributes ( Ch *&  text,
xml_node< Ch > *  node 
)
inlineprivate

◆ parse_node_contents()

template<class Ch = char>
template<int Flags>
void rapidxml::xml_document< Ch >::parse_node_contents ( Ch *&  text,
xml_node< Ch > *  node 
)
inlineprivate

◆ parse_pi()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_pi ( Ch *&  text)
inlineprivate

◆ parse_xml_declaration()

template<class Ch = char>
template<int Flags>
xml_node<Ch>* rapidxml::xml_document< Ch >::parse_xml_declaration ( Ch *&  text)
inlineprivate

◆ skip()

template<class Ch = char>
template<class StopPred , int Flags>
static void rapidxml::xml_document< Ch >::skip ( Ch *&  text)
inlinestaticprivate

◆ skip_and_expand_character_refs()

template<class Ch = char>
template<class StopPred , class StopPredPure , int Flags>
static Ch* rapidxml::xml_document< Ch >::skip_and_expand_character_refs ( Ch *&  text)
inlinestaticprivate

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