libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Protected Member Functions | Friends | List of all members
crn::xml::Element Class Reference

XML element. More...

#include <CRNXml.h>

+ Inheritance diagram for crn::xml::Element:
+ Collaboration diagram for crn::xml::Element:

Classes

class  Attribute
 

Public Member Functions

virtual ~Element () override
 Destructor. More...
 
 Element (const Element &)=default
 
 Element (Element &&)=default
 
Elementoperator= (const Element &)=default
 
Elementoperator= (Element &&)=default
 
StringUTF8 GetName () const
 Gets the label of the element. More...
 
void SetName (const StringUTF8 &s)
 Sets the label of the element. More...
 
Elementoperator++ ()
 Moves to the next sibling element. More...
 
Element operator++ (int)
 Moves to the next sibling element. More...
 
size_t GetNbSubnodes () const
 Returns the number of sub-nodes. More...
 
size_t GetNbSubelements () const
 Returns the number of sub-elements. More...
 
Node GetFirstChild ()
 Gets the first child node. More...
 
Node GetLastChild ()
 Gets the last child node. More...
 
Node BeginNode ()
 Gets the first child node. More...
 
Node EndNode ()
 Gets a null node. More...
 
Element GetFirstChildElement (const StringUTF8 &name="")
 Gets the first child element. More...
 
Element GetLastChildElement (const StringUTF8 &name="")
 Gets the last child element. More...
 
Element BeginElement ()
 Gets the first child element. More...
 
Element EndElement ()
 Gets a null node. More...
 
StringUTF8 GetFirstChildText ()
 Gets the first child as text. More...
 
Element PushBackElement (const StringUTF8 &name)
 Adds an element at the end of the children list. More...
 
Element PushFrontElement (const StringUTF8 &name)
 Adds an element at the front of the children list. More...
 
Element InsertElement (Node &n, const StringUTF8 &name)
 Inserts an element after a node. More...
 
Comment PushBackComment (const StringUTF8 &text)
 Adds a comment at the end of the children list. More...
 
Comment PushFrontComment (const StringUTF8 &text)
 Adds a comment at the front of the children list. More...
 
Comment InsertComment (Node &n, const StringUTF8 &text)
 Inserts a comment after a node. More...
 
Text PushBackText (const StringUTF8 &text, bool cdata=false)
 Adds a text at the end of the children list. More...
 
Text PushFrontText (const StringUTF8 &text, bool cdata=false)
 Adds a text at the front of the children list. More...
 
Text InsertText (Node &n, const StringUTF8 &text, bool cdata=false)
 Inserts a text after a node. More...
 
Node PushBackClone (Node &n, bool recursive=false)
 Adds a copy of a node at the end of the children list. More...
 
void Clear ()
 Removes all children. More...
 
void RemoveChild (Node &n)
 Removes a child node. More...
 
template<typename T >
GetAttribute (const StringUTF8 &name, bool silent=true) const
 Gets an attribute. More...
 
void SetAttribute (const StringUTF8 &name, const StringUTF8 &value)
 Sets the value of an attribute. More...
 
void RemoveAttribute (const StringUTF8 &name)
 Removes an attribute. More...
 
Attribute BeginAttribute ()
 Gets the first attribute. More...
 
Attribute EndAttribute ()
 Gets the null attribute. More...
 
template<>
StringUTF8 GetAttribute (const StringUTF8 &name, bool silent) const
 Gets an attribute. More...
 
- Public Member Functions inherited from crn::xml::Node
virtual ~Node ()
 Destructor. More...
 
 Node (const Node &)=default
 
 Node (Node &&)=default
 
Nodeoperator= (const Node &)=default
 
Nodeoperator= (Node &&)=default
 
bool IsElement ()
 Checks if the node is an element. More...
 
bool IsComment ()
 Checks if the node is a comment. More...
 
bool IsText ()
 Checks if the node is a text. More...
 
Element AsElement ()
 Converts to element. More...
 
Comment AsComment ()
 Converts to comment. More...
 
Text AsText ()
 Converts to text. More...
 
 operator bool () const noexcept
 Checks if the node is not null. More...
 
bool operator! () const noexcept
 Checks if the node is null. More...
 
bool operator== (const Node &other) const noexcept
 Comparison operator. More...
 
bool operator!= (const Node &other) const noexcept
 Comparison operator. More...
 
virtual StringUTF8 GetValue () const
 Gets the content of the node. More...
 
void SetValue (const StringUTF8 &s)
 Sets the content of the node. More...
 
Node GetParent ()
 Gets the parent node if any. More...
 
Node GetPreviousSibling ()
 Gets the previous sibling node. More...
 
Node GetNextSibling ()
 Gets the next sibling node. More...
 
Nodeoperator++ ()
 Moves to the next sibling node. More...
 
Node operator++ (int)
 Moves to the next sibling node. More...
 
Element GetNextSiblingElement (const StringUTF8 &name="")
 Gets the next sibling element. More...
 
Element GetPreviousSiblingElement (const StringUTF8 &name="")
 Gets the previous sibling element. More...
 

Protected Member Functions

 Element (tinyxml2::XMLElement *el, const SCharsetConverter &c)
 Constructor. More...
 
- Protected Member Functions inherited from crn::xml::Node
 Node (tinyxml2::XMLNode *n, const SCharsetConverter &c)
 Constructor. More...
 

Friends

class Node
 
class Document
 

Additional Inherited Members

- Protected Attributes inherited from crn::xml::Node
SCharsetConverter conv
 

Detailed Description

XML element.

An XML element

Version
1.0
Author
Yann LEYDIER
Date
August 2012

Definition at line 135 of file CRNXml.h.

Constructor & Destructor Documentation

virtual crn::xml::Element::~Element ( )
inlineoverridevirtual

Destructor.

Definition at line 139 of file CRNXml.h.

crn::xml::Element::Element ( const Element )
default
crn::xml::Element::Element ( Element &&  )
default
Element::Element ( tinyxml2::XMLElement el,
const SCharsetConverter &  c 
)
protected

Constructor.

Constructor

Parameters
[in]elthe inner element pointer
[in]ca character set converter

Definition at line 260 of file CRNXml.cpp.

Member Function Documentation

Element::Attribute Element::BeginAttribute ( )

Gets the first attribute.

Gets the first attribute

Returns
the first attribute

Definition at line 618 of file CRNXml.cpp.

Element crn::xml::Element::BeginElement ( )
inline

Gets the first child element.

Definition at line 174 of file CRNXml.h.

Node crn::xml::Element::BeginNode ( )
inline

Gets the first child node.

Definition at line 165 of file CRNXml.h.

void Element::Clear ( )

Removes all children.

Removes all children

Definition at line 572 of file CRNXml.cpp.

Element::Attribute Element::EndAttribute ( )

Gets the null attribute.

Gets the null attribute

Returns
the null attribute

Definition at line 626 of file CRNXml.cpp.

Element crn::xml::Element::EndElement ( )
inline

Gets a null node.

Definition at line 176 of file CRNXml.h.

Node crn::xml::Element::EndNode ( )
inline

Gets a null node.

Definition at line 167 of file CRNXml.h.

template<typename T >
T crn::xml::Element::GetAttribute ( const StringUTF8 name,
bool  silent = true 
) const
inline

Gets an attribute.

Exceptions
ExceptionInvalidArgumentempty attribute name
ExceptionNotFoundattribute not found
ExceptionDomaincannot convert attribute
Parameters
[in]namethe name of the attribute
[in]silentshall exceptions be dropped?
Returns
the attribute's value (or 0 if silent and not found or cannot convert)

Definition at line 219 of file CRNXml.h.

template<>
StringUTF8 crn::xml::Element::GetAttribute ( const StringUTF8 name,
bool  silent 
) const
inline

Gets an attribute.

Exceptions
ExceptionInvalidArgumentempty attribute name
ExceptionNotFoundattribute not found
ExceptionDomaincannot convert attribute
Parameters
[in]namethe name of the attribute
[in]silentshall exceptions be dropped?
Returns
the attribute's value (or 0 if silent and not found or cannot convert)

Definition at line 343 of file CRNXml.h.

Node Element::GetFirstChild ( )

Gets the first child node.

Gets the first child node

Returns
the first child node or null node

Definition at line 303 of file CRNXml.cpp.

Element Element::GetFirstChildElement ( const StringUTF8 name = "")

Gets the first child element.

Gets the first child element

Parameters
[in]namethe name of the element or empty string for any element
Returns
the first child element or null element

Definition at line 320 of file CRNXml.cpp.

StringUTF8 Element::GetFirstChildText ( )

Gets the first child as text.

Gets the first child as text

Exceptions
ExceptionNotFoundno child
ExceptionDomainfirst child is not Text
Returns
the text of the first child node

Definition at line 339 of file CRNXml.cpp.

Node Element::GetLastChild ( )

Gets the last child node.

Gets the last child node

Returns
the last child node or null node

Definition at line 311 of file CRNXml.cpp.

Element Element::GetLastChildElement ( const StringUTF8 name = "")

Gets the last child element.

Gets the last child element

Parameters
[in]namethe name of the element or empty string for any element
Returns
the last child element or null element

Definition at line 329 of file CRNXml.cpp.

StringUTF8 crn::xml::Element::GetName ( ) const
inline

Gets the label of the element.

Definition at line 146 of file CRNXml.h.

size_t crn::xml::Element::GetNbSubelements ( ) const
inline

Returns the number of sub-elements.

Definition at line 159 of file CRNXml.h.

size_t crn::xml::Element::GetNbSubnodes ( ) const
inline

Returns the number of sub-nodes.

Definition at line 157 of file CRNXml.h.

Comment Element::InsertComment ( Node n,
const StringUTF8 text 
)

Inserts a comment after a node.

Inserts a comment after a node

Exceptions
ExceptionNotFoundnode not found
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]nthe node after which the new comment will be inserted
[in]textthe content of the comment
Returns
a handle on the newly created comment

Definition at line 446 of file CRNXml.cpp.

Element Element::InsertElement ( Node n,
const StringUTF8 name 
)

Inserts an element after a node.

Inserts an element after a node

Exceptions
ExceptionInvalidArgumentnull node or empty element name
ExceptionNotFoundnode not found
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]nthe node after which the new element will be inserted
[in]namethe name of the element
Returns
a handle on the newly created element

Definition at line 393 of file CRNXml.cpp.

Text Element::InsertText ( Node n,
const StringUTF8 text,
bool  cdata = false 
)

Inserts a text after a node.

Inserts a text after a node

Exceptions
ExceptionInvalidArgumentnull node
ExceptionNotFoundnode not found
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]nthe node after which the new text will be inserted
[in]textthe content of the text
[in]cdatais the text stored as a CData?
Returns
a handle on the newly created text

Definition at line 502 of file CRNXml.cpp.

Element & Element::operator++ ( )

Moves to the next sibling element.

Moves to the next sibling element

Returns
the next element or null element

Definition at line 284 of file CRNXml.cpp.

Element Element::operator++ ( int  )

Moves to the next sibling element.

Moves to the next sibling element

Returns
the current element

Definition at line 293 of file CRNXml.cpp.

Element& crn::xml::Element::operator= ( const Element )
default
Element& crn::xml::Element::operator= ( Element &&  )
default
Node Element::PushBackClone ( Node n,
bool  recursive = false 
)

Adds a copy of a node at the end of the children list.

Adds a copy of a node at the end of the children list

Exceptions
ExceptionInvalidArgumentnull or invalid node
Parameters
[in]nthe node to copy
[in]recursiveshall the subelements be copied too? (only if n is an Element)
Returns
a handle on the newly created node

Definition at line 523 of file CRNXml.cpp.

Comment Element::PushBackComment ( const StringUTF8 text)

Adds a comment at the end of the children list.

Adds a comment at the end of the children list

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]textthe content of the comment
Returns
a handle on the newly created comment

Definition at line 416 of file CRNXml.cpp.

Element Element::PushBackElement ( const StringUTF8 name)

Adds an element at the end of the children list.

Adds an element at the end of the children list

Exceptions
ExceptionInvalidArgumentempty element name
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the element
Returns
a handle on the newly created element

Definition at line 355 of file CRNXml.cpp.

Text Element::PushBackText ( const StringUTF8 text,
bool  cdata = false 
)

Adds a text at the end of the children list.

Adds a text at the end of the children list

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]textthe content of the text
[in]cdatais the text stored as a CData?
Returns
a handle on the newly created text

Definition at line 467 of file CRNXml.cpp.

Comment Element::PushFrontComment ( const StringUTF8 text)

Adds a comment at the front of the children list.

Adds a comment at the front of the children list

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]textthe content of the comment
Returns
a handle on the newly created comment

Definition at line 430 of file CRNXml.cpp.

Element Element::PushFrontElement ( const StringUTF8 name)

Adds an element at the front of the children list.

Adds an element at the front of the children list

Exceptions
ExceptionInvalidArgumentempty element name
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the element
Returns
a handle on the newly created element

Definition at line 373 of file CRNXml.cpp.

Text Element::PushFrontText ( const StringUTF8 text,
bool  cdata = false 
)

Adds a text at the front of the children list.

Adds a text at the front of the children list

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]textthe content of the text
[in]cdatais the text stored as a CData?
Returns
a handle on the newly created text

Definition at line 483 of file CRNXml.cpp.

void Element::RemoveAttribute ( const StringUTF8 name)

Removes an attribute.

Removes an attribute

Exceptions
ExceptionInvalidArgumentempty attribute name
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the attribute

Definition at line 608 of file CRNXml.cpp.

void Element::RemoveChild ( Node n)

Removes a child node.

Removes a child node

Parameters
[in]nthe node to remove

Definition at line 581 of file CRNXml.cpp.

void Element::SetAttribute ( const StringUTF8 name,
const StringUTF8 value 
)

Sets the value of an attribute.

Sets the value of an attribute

Exceptions
ExceptionInvalidArgumentempty attribute name
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the attribute
[in]valuethe new value of the attribute

Definition at line 595 of file CRNXml.cpp.

void crn::xml::Element::SetName ( const StringUTF8 s)
inline

Sets the label of the element.

Definition at line 148 of file CRNXml.h.

Friends And Related Function Documentation

friend class Document
friend

Definition at line 333 of file CRNXml.h.

friend class Node
friend

Definition at line 332 of file CRNXml.h.


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