TSDuck v3.40-4034
MPEG Transport Stream Toolkit
|
Structured element in an XML document. More...
#include <tsxmlElement.h>
Public Member Functions | |
Element (const Element &other) | |
Copy constructor. | |
Element (Node *parent, const UString &name, CaseSensitivity attributeCase=CASE_INSENSITIVE, bool last=true) | |
Constructor. | |
Element (Report &report=(ts::NullReport::Instance()), size_t line=0, CaseSensitivity attributeCase=CASE_INSENSITIVE) | |
Constructor. | |
Element * | addElement (const UString &childName) |
Add a new child element at the end of children. | |
Text * | addHexaText (const ByteBlock &data, bool onlyNotEmpty=false) |
Add a new text containing hexadecimal data inside this node. | |
Text * | addHexaText (const void *data, size_t size, bool onlyNotEmpty=false) |
Add a new text containing hexadecimal data inside this node. | |
Text * | addHexaTextChild (const UString &name, const ByteBlock &data, bool onlyNotEmpty=false) |
Add a new child element containing an hexadecimal data text. | |
Text * | addHexaTextChild (const UString &name, const void *data, size_t size, bool onlyNotEmpty=false) |
Add a new child element containing an hexadecimal data text. | |
Text * | addText (const UString &text, bool onlyNotEmpty=false) |
Add a new text inside this node. | |
const Attribute & | attribute (const UString &attributeName, bool silent=false) const |
Get an attribute. | |
size_t | childrenCount () const |
Get the number of children. | |
virtual void | clear () override |
Clear the content of the node. | |
virtual Node * | clone () const override |
Clone the content of the node in a dynamically allocated object. | |
UString | debug () const |
Build a debug string for the node. | |
void | deleteAttribute (const UString &name) |
Delete an attribute. | |
size_t | depth () const |
Get the depth of an XML element. | |
Document * | document () |
Get the document into which the node is located. | |
const Document * | document () const |
Get the document into which the node is located. | |
Element * | findFirstChild (const UString &name, bool silent=false) |
Find the first child element by name, case-insensitive. | |
const Element * | findFirstChild (const UString &name, bool silent=false) const |
Find the first child element by name, case-insensitive. | |
Node * | firstChild () |
Get the first child of a node. | |
const Node * | firstChild () const |
Get the first child of a node. | |
Element * | firstChildElement () |
Get the first child Element of a node. | |
const Element * | firstChildElement () const |
Get the first child Element of a node. | |
bool | getAttribute (UString &value, const UString &name, bool required=false, const UString &defValue=UString(), size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get a string attribute of an XML element. | |
void | getAttributes (std::map< UString, UString > &attr) const |
Get the list of all attributes. | |
size_t | getAttributesCount () const |
Get the number of attributes in the element. | |
void | getAttributesNames (UStringList &names) const |
Get the list of all attribute names. | |
void | getAttributesNamesInModificationOrder (UStringList &names) const |
Get the list of all attribute names, sorted by modification order. | |
bool | getBoolAttribute (bool &value, const UString &name, bool required=false, bool defValue=false) const |
Get a boolean attribute of an XML element. | |
bool | getChildren (ElementVector &children, const UString &name, size_t minCount=0, size_t maxCount=UNLIMITED) const |
Find all children elements by name, case-insensitive. | |
template<class Rep , class Period > | |
bool | getChronoAttribute (cn::duration< Rep, Period > &value, const UString &name, bool required=false, const cn::duration< Rep, Period > &defValue=cn::duration< Rep, Period >::zero(), const cn::duration< Rep, Period > &minValue=cn::duration< Rep, Period >::min(), const cn::duration< Rep, Period > &maxValue=cn::duration< Rep, Period >::max()) const |
Get a std::chrono::duration attribute of an XML element. | |
template<typename INT , typename INT1 = INT, typename INT2 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> && ts::int_enum<INT2> | |
bool | getConditionalIntAttribute (std::optional< INT > &value, const UString &name, bool condition, INT1 minValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::min(), INT2 maxValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::max()) const |
Get an integer or enum attribute of an XML element, based on a condition. | |
bool | getDateAttribute (Time &value, const UString &name, bool required=false, const Time &defValue=Time()) const |
Get a date (without hours) attribute of an XML element. | |
bool | getDateTimeAttribute (Time &value, const UString &name, bool required=false, const Time &defValue=Time()) const |
Get a date/time attribute of an XML element. | |
template<typename INT , typename INT1 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> | |
bool | getEnumAttribute (INT &value, const Enumeration &definition, const UString &name, bool required=false, INT1 defValue=INT(0)) const |
Get an enumeration attribute of an XML element. | |
template<typename INT , typename INT1 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> | |
bool | getEnumAttribute (std::optional< INT > &value, const Enumeration &definition, const UString &name, bool required=false, INT1 defValue=INT(0)) const |
Get an enumeration attribute of an XML element. | |
template<typename FLT , typename FLT1 = FLT, typename FLT2 = FLT, typename FLT3 = FLT> requires std::floating_point<FLT> && std::is_arithmetic_v<FLT1> && std::is_arithmetic_v<FLT2> && std::is_arithmetic_v<FLT3> | |
bool | getFloatAttribute (FLT &value, const UString &name, bool required=false, FLT1 defValue=static_cast< FLT >(0.0), FLT2 minValue=std::numeric_limits< FLT >::lowest(), FLT3 maxValue=std::numeric_limits< FLT >::max()) const |
Get a floating-point attribute of an XML element. | |
bool | getHexaText (ByteBlock &data, size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get and interpret the hexadecimal data inside the element. | |
bool | getHexaTextChild (ByteBlock &data, const UString &name, bool required=false, size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get text in a child containing hexadecimal data. | |
template<typename INT , typename INT1 = INT, typename INT2 = INT, typename INT3 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> && ts::int_enum<INT2> && ts::int_enum<INT3> | |
bool | getIntAttribute (INT &value, const UString &name, bool required=false, INT1 defValue=static_cast< INT >(0), INT2 minValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::min(), INT3 maxValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::max()) const |
Get an integer or enum attribute of an XML element. | |
template<typename INT , typename INT1 = INT, typename INT2 = INT, typename INT3 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> && ts::int_enum<INT2> && ts::int_enum<INT3> | |
bool | getIntAttribute (std::optional< INT > &value, const UString &name, bool required=false, INT1 defValue=static_cast< INT >(0), INT2 minValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::min(), INT3 maxValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::max()) const |
Get an integer or enum attribute of an XML element. | |
bool | getIPAttribute (IPAddress &value, const UString &name, bool required=false, const IPAddress &defValue=IPAddress()) const |
Get an IPv4 or IPv6 address attribute of an XML element in numerical format or host name. | |
bool | getMACAttribute (MACAddress &value, const UString &name, bool required=false, const MACAddress &defValue=MACAddress()) const |
Get a MAC address attribute of an XML element in "x:x:x:x:x:x" format. | |
bool | getOptionalAttribute (std::optional< UString > &value, const UString &name, size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get an optional string attribute of an XML element. | |
bool | getOptionalBoolAttribute (std::optional< bool > &value, const UString &name) const |
Get an optional boolean attribute of an XML element. | |
bool | getOptionalDateAttribute (std::optional< Time > &value, const UString &name) const |
Get an optional date (without hours) attribute of an XML element. | |
bool | getOptionalDateTimeAttribute (std::optional< Time > &value, const UString &name) const |
Get an optional date/time attribute of an XML element. | |
template<typename INT > requires ts::int_enum<INT> | |
bool | getOptionalEnumAttribute (std::optional< INT > &value, const Enumeration &definition, const UString &name) const |
Get an optional enumeration attribute of an XML element. | |
template<typename FLT , typename FLT1 = FLT, typename FLT2 = FLT> requires std::floating_point<FLT> && std::is_arithmetic_v<FLT1> && std::is_arithmetic_v<FLT2> | |
bool | getOptionalFloatAttribute (std::optional< FLT > &value, const UString &name, FLT1 minValue=std::numeric_limits< FLT >::lowest(), FLT2 maxValue=std::numeric_limits< FLT >::max()) const |
Get an optional floating-point attribute of an XML element. | |
template<typename INT , typename INT1 = INT, typename INT2 = INT> requires ts::int_enum<INT> && ts::int_enum<INT1> && ts::int_enum<INT2> | |
bool | getOptionalIntAttribute (std::optional< INT > &value, const UString &name, INT1 minValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::min(), INT2 maxValue=std::numeric_limits< typename ts::underlying_type< INT >::type >::max()) const |
Get an optional integer or enum attribute of an XML element. | |
template<class Rep , class Period > | |
bool | getOptionalTimeAttribute (std::optional< cn::duration< Rep, Period > > &value, const UString &name) const |
Get an optional time attribute of an XML element in "hh:mm:ss" format. | |
bool | getText (UString &data, bool trim=false, size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get text inside an element. | |
bool | getTextChild (UString &data, const UString &name, bool trim=false, bool required=false, const UString &defValue=UString(), size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get text in a child of an element. | |
template<class Rep , class Period > | |
bool | getTimeAttribute (cn::duration< Rep, Period > &value, const UString &name, bool required=false) const |
Get a time attribute of an XML element in "hh:mm:ss" format. | |
template<class Rep1 , class Period1 , class Rep2 , class Period2 > | |
bool | getTimeAttribute (cn::duration< Rep1, Period1 > &value, const UString &name, bool required, const cn::duration< Rep2, Period2 > &defValue) const |
Get a time attribute of an XML element in "hh:mm:ss" format. | |
bool | getVariableAttribute (std::optional< UString > &value, const UString &name, bool required=false, const UString &defValue=UString(), size_t minSize=0, size_t maxSize=UNLIMITED) const |
Get an optional attribute of an XML element. | |
template<typename FLT , typename FLT1 = FLT, typename FLT2 = FLT, typename FLT3 = FLT> requires std::floating_point<FLT> && std::is_arithmetic_v<FLT1> && std::is_arithmetic_v<FLT2> && std::is_arithmetic_v<FLT3> | |
bool | getVariableFloatAttribute (std::optional< FLT > &value, const UString &name, bool required=false, FLT1 defValue=static_cast< FLT >(0), FLT2 minValue=std::numeric_limits< FLT >::lowest(), FLT3 maxValue=std::numeric_limits< FLT >::max()) const |
Get an optional floating-point attribute of an XML element. | |
bool | hasAttribute (const UString &attributeName) const |
Check if an attribute exists in the element. | |
bool | hasAttribute (const UString &attributeName, const UString &value, bool similar=false) const |
Check if an attribute exists in the element and has the specified value. | |
bool | hasChildElement (const UString &name) const |
Check if the element contains at least 1 named child element, case-insensitive. | |
bool | hasChildren () const |
Check if the node has children. | |
bool | haveSameName (const Element *other) const |
Check if two XML elements have the same name, case-insensitive. | |
Node * | lastChild () |
Get the last child. | |
const Node * | lastChild () const |
Get the last child. | |
size_t | lineNumber () const |
Get the line number in input document. | |
bool | merge (Element *other, MergeAttributes attrOptions=MergeAttributes::ADD) |
Recursively merge another element into this one. | |
void | move (Node *newSibling, bool before) |
Move the node before or after another node, potentially to a new parent. | |
void | moveAfter (Node *newSibling) |
Move the node after another node, potentially to a new parent. | |
void | moveBefore (Node *newSibling) |
Move the node before another node, potentially to a new parent. | |
const UString & | name () const |
Get the element name. | |
Node * | nextSibling () |
Get the next sibling node. | |
const Node * | nextSibling () const |
Get the next sibling node. | |
Element * | nextSiblingElement () |
Find the next sibling element. | |
const Element * | nextSiblingElement () const |
Find the next sibling element. | |
virtual UString | oneLiner () const |
Format the value as a one-liner XML text. | |
Node * | parent () |
Get the parent's node. | |
const Node * | parent () const |
Get the parent's node. | |
const UString & | parentName () const |
Get the parent name. | |
bool | preserveSpace () const |
Check if the node or one of its ancestors has attribute xml:space="preserve". | |
Node * | previousSibling () |
Get the previous sibling node. | |
const Node * | previousSibling () const |
Get the previous sibling node. | |
Element * | previousSiblingElement () |
Find the previous sibling element. | |
const Element * | previousSiblingElement () const |
Find the previous sibling element. | |
virtual void | print (TextFormatter &output, bool keepNodeOpen=false) const override |
Format the node for an output XML document. | |
virtual void | printClose (TextFormatter &output, size_t levels=std::numeric_limits< size_t >::max()) const override |
Print the closing tags for the node. | |
void | removeComments (bool recurse) |
Remove all comments in the XML node. | |
void | reparent (Node *newParent, bool last=true) |
Attach the node to a new parent. | |
Report & | report () const |
Get a reference to the report object for the XML node. | |
bool | ringAlone () const |
Check if the node is alone in its own ring. | |
void | ringInsertAfter (RingNode *o) |
Insert this object in a ring after the specified node. | |
void | ringInsertBefore (RingNode *o) |
Insert this object in a ring before the specified node. | |
template<typename T > | |
T * | ringNext () |
Get the next node in the ring. | |
template<typename T > | |
const T * | ringNext () const |
Get the next node in the ring. | |
template<typename T > | |
T * | ringPrevious () |
Get the previous node in the ring. | |
template<typename T > | |
const T * | ringPrevious () const |
Get the previous node in the ring. | |
void | ringRemove () |
Remove the node from the ring it belongs to and creates its own ring. | |
size_t | ringSize () const |
Count the number of element in the ring. | |
void | ringSwap (RingNode *o) |
Swap this object and another one in their rings. | |
void | setAttribute (const UString &name, const UString &value, bool onlyIfNotEmpty=false) |
Set an attribute. | |
void | setBoolAttribute (const UString &name, bool value) |
Set a bool attribute to a node. | |
template<class Rep , class Period > | |
void | setChronoAttribute (const UString &name, cn::duration< Rep, Period > value, bool hexa=false) |
Set an attribute with a std::chrono::duration value to a node. | |
void | setDateAttribute (const UString &name, const Time &value) |
Set a date (xithout hours) attribute of an XML element. | |
void | setDateTimeAttribute (const UString &name, const Time &value) |
Set a date/time attribute of an XML element. | |
template<typename INT > requires ts::int_enum<INT> | |
void | setEnumAttribute (const Enumeration &definition, const UString &name, INT value) |
Set an enumeration attribute of a node. | |
template<typename FLT > requires std::floating_point<FLT> | |
void | setFloatAttribute (const UString &name, FLT value, size_t width=0, size_t precision=6, bool force_sign=false) |
Set an attribute with a floating-point value to a node. | |
template<typename INT > requires std::integral<INT> | |
void | setIntAttribute (const UString &name, INT value, bool hexa=false) |
Set an attribute with an integer value to a node. | |
void | setIPAttribute (const UString &name, const IPAddress &value) |
Set an IPv4 or IPv6 address attribute of an XML element. | |
void | setMACAttribute (const UString &name, const MACAddress &value) |
Set a MAC address attribute of an XML element in "x:x:x:x:x:x" format. | |
void | setOptionalAttribute (const UString &name, const std::optional< UString > &value) |
Set an optional attribute to a node. | |
void | setOptionalBoolAttribute (const UString &name, const std::optional< bool > &value) |
Set an optional bool attribute to a node. | |
void | setOptionalDateAttribute (const UString &name, const std::optional< Time > &value) |
Set an optional date (xithout hours) attribute of an XML element. | |
void | setOptionalDateTimeAttribute (const UString &name, const std::optional< Time > &value) |
Set an optional date/time attribute of an XML element. | |
template<typename INT > requires ts::int_enum<INT> | |
void | setOptionalEnumAttribute (const Enumeration &definition, const UString &name, const std::optional< INT > &value) |
Set an optional attribute with an enumeration attribute to a node. | |
template<typename FLT > requires std::floating_point<FLT> | |
void | setOptionalFloatAttribute (const UString &name, const std::optional< FLT > &value, size_t width=0, size_t precision=6, bool force_sign=false) |
Set an optional attribute with a floating-point value to a node. | |
template<typename INT > requires std::integral<INT> | |
void | setOptionalIntAttribute (const UString &name, const std::optional< INT > &value, bool hexa=false) |
Set an optional attribute with an integer value to a node. | |
template<class Rep , class Period > | |
void | setOptionalTimeAttribute (const UString &name, const std::optional< cn::duration< Rep, Period > > &value) |
Set an optional time attribute of an XML element in "hh:mm:ss" format. | |
template<class Rep , class Period > | |
void | setTimeAttribute (const UString &name, const cn::duration< Rep, Period > &value) |
Set a time attribute of an XML element in "hh:mm:ss" format. | |
void | setValue (const UString &value) |
Set the value of the node. | |
void | sort (const UString &name=UString()) |
Sort children elements by alphabetical order of tag name. | |
virtual bool | stickyOutput () const |
Check if the text shall be stuck to other elements in XML output. | |
UString | text (bool trim=false) const |
Get text inside an element. | |
virtual const Tweaks & | tweaks () const |
Get a constant reference to the current XML parsing and formatting tweaks for this node. | |
virtual UString | typeName () const override |
Return a node type name, mainly for debug purpose. | |
const UString & | value () const |
Get the value of the node. | |
Protected Member Functions | |
Node * | identifyNextNode (TextParser &parser) |
Identify the next token in the document. | |
virtual bool | parseChildren (TextParser &parser) |
Parse children nodes and add them to the node. | |
virtual bool | parseNode (TextParser &parser, const Node *parent) override |
Parse the node. | |
void | setPreserveSpace (bool on) |
Called by the subclass when its spaces shall be preserved. | |
Structured element in an XML document.
|
explicit |
Constructor.
[in,out] | report | Where to report errors. |
[in] | line | Line number in input document. |
[in] | attributeCase | State if attribute names are stored with case sensitivity. |
ts::xml::Element::Element | ( | Node * | parent, |
const UString & | name, | ||
CaseSensitivity | attributeCase = CASE_INSENSITIVE , |
||
bool | last = true |
||
) |
Constructor.
[in,out] | parent | The parent into which the element is added. |
[in] | name | Name of the element. |
[in] | attributeCase | State if attribute names are stored wit case sensitivity. |
[in] | last | If true, the child is added at the end of the list of children. If false, it is added at the beginning. |
ts::xml::Element::Element | ( | const Element & | other | ) |
Copy constructor.
[in] | other | Other instance to copy. |
|
inline |
Get the element name.
This is the same as the node value.
const UString & ts::xml::Element::parentName | ( | ) | const |
|
inline |
Check if two XML elements have the same name, case-insensitive.
[in] | other | Another XML element. |
|
inline |
Find the first child element by name, case-insensitive.
[in] | name | Name of the child element to search. If empty, get the first element. |
[in] | silent | If true, do not report error. |
Find the first child element by name, case-insensitive.
[in] | name | Name of the child element to search. If empty, get the first element. |
[in] | silent | If true, do not report error. |
bool ts::xml::Element::getChildren | ( | ElementVector & | children, |
const UString & | name, | ||
size_t | minCount = 0 , |
||
size_t | maxCount = UNLIMITED |
||
) | const |
Find all children elements by name, case-insensitive.
[out] | children | Returned vector of all children. |
[in] | name | Name of the child element to search. |
[in] | minCount | Minimum required number of elements of that name. |
[in] | maxCount | Maximum allowed number of elements of that name. |
bool ts::xml::Element::hasChildElement | ( | const UString & | name | ) | const |
Check if the element contains at least 1 named child element, case-insensitive.
[in] | name | Name of the child element to search. |
bool ts::xml::Element::getTextChild | ( | UString & | data, |
const UString & | name, | ||
bool | trim = false , |
||
bool | required = false , |
||
const UString & | defValue = UString() , |
||
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get text in a child of an element.
[out] | data | The content of the text in the child element. |
[in] | name | Name of the child element to search. |
[in] | trim | If true, remove leading and trailing spaces. |
[in] | required | If true, generate an error if the child element is not found. |
[in] | defValue | Default value to return if the child element is not present. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
bool ts::xml::Element::getText | ( | UString & | data, |
bool | trim = false , |
||
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get text inside an element.
In practice, concatenate the content of all Text children inside the element.
[out] | data | The content of the text children. |
[in] | trim | If true, remove leading and trailing spaces. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
UString ts::xml::Element::text | ( | bool | trim = false | ) | const |
Get text inside an element.
In practice, concatenate the content of all Text children inside the element.
[in] | trim | If true, remove leading and trailing spaces. |
bool ts::xml::Element::getHexaTextChild | ( | ByteBlock & | data, |
const UString & | name, | ||
bool | required = false , |
||
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get text in a child containing hexadecimal data.
[out] | data | The content of the text in the child element. |
[in] | name | Name of the child element to search. |
[in] | required | If true, generate an error if the child element is not found. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
bool ts::xml::Element::getHexaText | ( | ByteBlock & | data, |
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get and interpret the hexadecimal data inside the element.
In practice, concatenate the content of all Text children inside the element and interpret the result as hexadecimal data.
[out] | data | Buffer receiving the decoded hexadecimal data. |
[in] | minSize | Minimum size of the returned data. |
[in] | maxSize | Maximum size of the returned data. |
Add a new child element at the end of children.
[in] | childName | Name of new child element to create. |
Add a new text inside this node.
[in] | text | Text string to add. |
[in] | onlyNotEmpty | When true, do not add the text if the string is empty. |
Text * ts::xml::Element::addHexaText | ( | const void * | data, |
size_t | size, | ||
bool | onlyNotEmpty = false |
||
) |
Add a new text containing hexadecimal data inside this node.
[in] | data | Address of binary data. |
[in] | size | Size in bytes of binary data. |
[in] | onlyNotEmpty | When true, do not add the child element if the data is empty. |
Add a new text containing hexadecimal data inside this node.
[in] | data | Binary data. |
[in] | onlyNotEmpty | When true, do not add the child element if the data is empty. |
Text * ts::xml::Element::addHexaTextChild | ( | const UString & | name, |
const void * | data, | ||
size_t | size, | ||
bool | onlyNotEmpty = false |
||
) |
Add a new child element containing an hexadecimal data text.
[in] | name | Name of the child element to search. |
[in] | data | Address of binary data. |
[in] | size | Size in bytes of binary data. |
[in] | onlyNotEmpty | When true, do not add the child element if the data is empty. |
Text * ts::xml::Element::addHexaTextChild | ( | const UString & | name, |
const ByteBlock & | data, | ||
bool | onlyNotEmpty = false |
||
) |
Add a new child element containing an hexadecimal data text.
[in] | name | Name of the child element to search. |
[in] | data | Binary data. |
[in] | onlyNotEmpty | When true, do not add the child element if the data is empty. |
bool ts::xml::Element::hasAttribute | ( | const UString & | attributeName | ) | const |
Check if an attribute exists in the element.
[in] | attributeName | Attribute name. |
bool ts::xml::Element::hasAttribute | ( | const UString & | attributeName, |
const UString & | value, | ||
bool | similar = false |
||
) | const |
Check if an attribute exists in the element and has the specified value.
[in] | attributeName | Attribute name. |
[in] | value | Expected value. |
[in] | similar | If true, the comparison between the actual and expected values is performed case-insensitive and ignoring blanks. If false, a strict comparison is performed. |
void ts::xml::Element::deleteAttribute | ( | const UString & | name | ) |
Delete an attribute.
[in] | name | Attribute name to delete. |
|
inline |
|
inline |
|
inline |
|
inline |
Set an attribute with a floating-point value to a node.
FLT | A floating-point type. |
|
inline |
Set an optional attribute with a floating-point value to a node.
FLT | A floating-point type. |
[in] | name | Attribute name. |
[in] | value | Attribute optional value. If the variable is not set, no attribute is set. |
[in] | width | Width of the formatted number, not including the optional prefix and separator. |
[in] | precision | Precision to use after the decimal point. Default is 6 digits. |
[in] | force_sign | If true, force a '+' sign for positive values. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
bool ts::xml::Element::getAttribute | ( | UString & | value, |
const UString & | name, | ||
bool | required = false , |
||
const UString & | defValue = UString() , |
||
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get a string attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
bool ts::xml::Element::getOptionalAttribute | ( | std::optional< UString > & | value, |
const UString & | name, | ||
size_t | minSize = 0 , |
||
size_t | maxSize = UNLIMITED |
||
) | const |
Get an optional string attribute of an XML element.
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | name | Name of the attribute. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
|
inline |
Get an optional attribute of an XML element.
getVariableAttribute() is different from getOptionalAttribute() in the result. With getOptionalAttribute(), if the attribute is missing, the std::optional is unset. With getVariableAttribute(), if the attribute is missing, the std::optional is set with the default value.
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minSize | Minimum allowed size for the value string. |
[in] | maxSize | Maximum allowed size for the value string. |
bool ts::xml::Element::getBoolAttribute | ( | bool & | value, |
const UString & | name, | ||
bool | required = false , |
||
bool | defValue = false |
||
) | const |
Get a boolean attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getOptionalBoolAttribute | ( | std::optional< bool > & | value, |
const UString & | name | ||
) | const |
Get an optional boolean attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
bool ts::xml::Element::getIntAttribute | ( | INT & | value, |
const UString & | name, | ||
bool | required = false , |
||
INT1 | defValue = static_cast<INT>(0) , |
||
INT2 | minValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::min() , |
||
INT3 | maxValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::max() |
||
) | const |
Get an integer or enum attribute of an XML element.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
|
inline |
Get an integer or enum attribute of an XML element.
INT | An integer type. |
[out] | value | Returned value of the attribute. Always set, possibly to the default value. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getOptionalIntAttribute | ( | std::optional< INT > & | value, |
const UString & | name, | ||
INT1 | minValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::min() , |
||
INT2 | maxValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::max() |
||
) | const |
Get an optional integer or enum attribute of an XML element.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | name | Name of the attribute. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getConditionalIntAttribute | ( | std::optional< INT > & | value, |
const UString & | name, | ||
bool | condition, | ||
INT1 | minValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::min() , |
||
INT2 | maxValue = std::numeric_limits<typename ts::underlying_type<INT>::type>::max() |
||
) | const |
Get an integer or enum attribute of an XML element, based on a condition.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | name | Name of the attribute. |
[in] | condition | If true, the attribute must be present. If false, the attribute must nbot be present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getEnumAttribute | ( | INT & | value, |
const Enumeration & | definition, | ||
const UString & | name, | ||
bool | required = false , |
||
INT1 | defValue = INT(0) |
||
) | const |
Get an enumeration attribute of an XML element.
Integer literals and integer values are accepted in the attribute.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. |
[in] | definition | The definition of enumeration values. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
|
inline |
Get an enumeration attribute of an XML element.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. Always set, possibly to the default value. |
[in] | definition | The definition of enumeration values. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getOptionalEnumAttribute | ( | std::optional< INT > & | value, |
const Enumeration & | definition, | ||
const UString & | name | ||
) | const |
Get an optional enumeration attribute of an XML element.
Integer literals and integer values are accepted in the attribute.
INT | An integer or enum type. |
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | definition | The definition of enumeration values. |
[in] | name | Name of the attribute. |
bool ts::xml::Element::getFloatAttribute | ( | FLT & | value, |
const UString & | name, | ||
bool | required = false , |
||
FLT1 | defValue = static_cast<FLT>(0.0) , |
||
FLT2 | minValue = std::numeric_limits<FLT>::lowest() , |
||
FLT3 | maxValue = std::numeric_limits<FLT>::max() |
||
) | const |
Get a floating-point attribute of an XML element.
FLT | A floating-point type. |
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getOptionalFloatAttribute | ( | std::optional< FLT > & | value, |
const UString & | name, | ||
FLT1 | minValue = std::numeric_limits<FLT>::lowest() , |
||
FLT2 | maxValue = std::numeric_limits<FLT>::max() |
||
) | const |
Get an optional floating-point attribute of an XML element.
FLT | A floating-point type. |
[out] | value | Returned value of the attribute. If the attribute is not present, the variable is reset. |
[in] | name | Name of the attribute. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
|
inline |
Get an optional floating-point attribute of an XML element.
getVariableFloatAttribute() is different from getOptionalFloatAttribute() in the result. With getOptionalFloatAttribute(), if the attribute is missing, the std::optional is unset. With getVariableFloatAttribute(), if the attribute is missing, the std::optional is set with the default value.
FLT | A floating-point type. |
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getChronoAttribute | ( | cn::duration< Rep, Period > & | value, |
const UString & | name, | ||
bool | required = false , |
||
const cn::duration< Rep, Period > & | defValue = cn::duration<Rep, Period>::zero() , |
||
const cn::duration< Rep, Period > & | minValue = cn::duration<Rep, Period>::min() , |
||
const cn::duration< Rep, Period > & | maxValue = cn::duration<Rep, Period>::max() |
||
) | const |
Get a std::chrono::duration attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
[in] | minValue | Minimum allowed value for the attribute. |
[in] | maxValue | Maximum allowed value for the attribute. |
bool ts::xml::Element::getDateTimeAttribute | ( | Time & | value, |
const UString & | name, | ||
bool | required = false , |
||
const Time & | defValue = Time() |
||
) | const |
Get a date/time attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getOptionalDateTimeAttribute | ( | std::optional< Time > & | value, |
const UString & | name | ||
) | const |
Get an optional date/time attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
bool ts::xml::Element::getDateAttribute | ( | Time & | value, |
const UString & | name, | ||
bool | required = false , |
||
const Time & | defValue = Time() |
||
) | const |
Get a date (without hours) attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getOptionalDateAttribute | ( | std::optional< Time > & | value, |
const UString & | name | ||
) | const |
Get an optional date (without hours) attribute of an XML element.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
|
inline |
Get a time attribute of an XML element in "hh:mm:ss" format.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
bool ts::xml::Element::getTimeAttribute | ( | cn::duration< Rep1, Period1 > & | value, |
const UString & | name, | ||
bool | required, | ||
const cn::duration< Rep2, Period2 > & | defValue | ||
) | const |
Get a time attribute of an XML element in "hh:mm:ss" format.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getOptionalTimeAttribute | ( | std::optional< cn::duration< Rep, Period > > & | value, |
const UString & | name | ||
) | const |
Get an optional time attribute of an XML element in "hh:mm:ss" format.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
bool ts::xml::Element::getIPAttribute | ( | IPAddress & | value, |
const UString & | name, | ||
bool | required = false , |
||
const IPAddress & | defValue = IPAddress() |
||
) | const |
Get an IPv4 or IPv6 address attribute of an XML element in numerical format or host name.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
bool ts::xml::Element::getMACAttribute | ( | MACAddress & | value, |
const UString & | name, | ||
bool | required = false , |
||
const MACAddress & | defValue = MACAddress() |
||
) | const |
Get a MAC address attribute of an XML element in "x:x:x:x:x:x" format.
[out] | value | Returned value of the attribute. |
[in] | name | Name of the attribute. |
[in] | required | If true, generate an error if the attribute is not found. |
[in] | defValue | Default value to return if the attribute is not present. |
void ts::xml::Element::getAttributesNames | ( | UStringList & | names | ) | const |
Get the list of all attribute names.
[out] | names | Returned list of all attribute names. |
Get the list of all attributes.
[out] | attr | Returned map of all attribute names (index in the map) and corresponding values. |
void ts::xml::Element::getAttributesNamesInModificationOrder | ( | UStringList & | names | ) | const |
Get the list of all attribute names, sorted by modification order.
The method is slower than getAttributesNames().
[out] | names | Returned list of all attribute names. |
|
inline |
Get the number of attributes in the element.
bool ts::xml::Element::merge | ( | Element * | other, |
MergeAttributes | attrOptions = MergeAttributes::ADD |
||
) |
Recursively merge another element into this one.
[in,out] | other | Another element to merge. The other object is destroyed, some of its nodes are reparented into the main object. |
[in] | attrOptions | What to do with attributes when merging nodes with identical tags. |
Sort children elements by alphabetical order of tag name.
[in] | name | When this parameter is not empty, recursively search for elements with that tag name and sort their children elements. |
|
overridevirtual |
Clone the content of the node in a dynamically allocated object.
This virtual method must be implemented by subclasses to allocate a object of the right class.
Implements ts::xml::Node.
|
overridevirtual |
Clear the content of the node.
The node becomes empty but remains attached to its parent.
Reimplemented from ts::xml::Node.
|
overridevirtual |
|
overridevirtual |
Format the node for an output XML document.
[in,out] | output | The output object to format the XML document. |
[in] | keepNodeOpen | If true, keep the node open so that children may be printed later. |
Implements ts::xml::Node.
|
overridevirtual |
Print the closing tags for the node.
Typically used after print() when keepNodeOpen was true. The default implementation is to do nothing. Subclasses may replace this.
[in,out] | output | The output object to format the XML document. |
[in] | levels | Number of levels to close. By default, close the complete document. If zero, no output is produced. |
Reimplemented from ts::xml::Node.
|
overrideprotectedvirtual |
Parse the node.
[in,out] | parser | The document parser. On input, the current position of the parser after the tag which identified the node ("<?", "<!- -", etc.) On output, it must be after the last character of the node. |
[in] | parent | Candidate parent node, for information only, do not modify. Can be null. |
Implements ts::xml::Node.
|
inlineinherited |
Get the line number in input document.
|
inherited |
Attach the node to a new parent.
The node is first detached from its previous parent.
[in,out] | newParent | New parent. If zero, the node becomes orphan. In that case, the node will no longer be freed by its parent and must be explicitly deleted. |
[in] | last | If true, the child is added at the end of the list of children. If false, it is added at the beginning. |
|
inlineinherited |
Move the node before another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved before this one. |
|
inlineinherited |
Move the node after another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved after this one. |
|
inherited |
Move the node before or after another node, potentially to a new parent.
[in,out] | newSibling | A new sibling. The node will be moved before or after this one. |
[in] | before | If true, move the node before newSibling, after it otherwise. |
|
inlineinherited |
Get the parent's node.
|
inlineinherited |
Get the parent's node.
|
inlineinherited |
Get the document into which the node is located.
|
inherited |
Get the document into which the node is located.
|
virtualinherited |
Get a constant reference to the current XML parsing and formatting tweaks for this node.
Reimplemented in ts::xml::Document.
|
inherited |
Get the depth of an XML element.
|
inherited |
Check if the node or one of its ancestors has attribute xml:space="preserve".
|
inlineinherited |
Check if the node has children.
|
inlineinherited |
Get the number of children.
|
inlineinherited |
Get the first child of a node.
|
inlineinherited |
Get the first child of a node.
|
inlineinherited |
Get the last child.
|
inlineinherited |
Get the last child.
|
inlineinherited |
Get the next sibling node.
|
inherited |
Get the next sibling node.
|
inlineinherited |
Get the previous sibling node.
|
inherited |
Get the previous sibling node.
|
inlineinherited |
|
inherited |
|
inlineinherited |
Find the next sibling element.
|
inherited |
Find the next sibling element.
|
inlineinherited |
Find the previous sibling element.
|
inherited |
Find the previous sibling element.
|
inlineinherited |
Get the value of the node.
The semantic of the value depends on the node subclass:
|
inlineinherited |
|
inherited |
Remove all comments in the XML node.
[in] | recurse | If true, apply recursively to all children nodes. |
|
virtualinherited |
Format the value as a one-liner XML text.
|
virtualinherited |
Check if the text shall be stuck to other elements in XML output.
Reimplemented in ts::xml::Text.
|
inherited |
Build a debug string for the node.
|
inlineinherited |
Get a reference to the report object for the XML node.
|
protectedinherited |
Identify the next token in the document.
[in,out] | parser | The document parser. |
|
protectedvirtualinherited |
Parse children nodes and add them to the node.
Stop either at end of document or before a "</" sequence or on error.
[in,out] | parser | The document parser. |
|
inlineprotectedinherited |
Called by the subclass when its spaces shall be preserved.
Typically called when xml:space="preserve" is encountered.
[in] | on | True is spaces shall be preserved. |
|
inlineinherited |
Check if the node is alone in its own ring.
|
inherited |
Insert this object in a ring after the specified node.
[in] | o | A node of a ring. This object is inserted after o in the ring. |
|
inherited |
Insert this object in a ring before the specified node.
[in] | o | A node of a ring. This object is inserted before o in the ring. |
|
inherited |
Swap this object and another one in their rings.
If the two objects belong to the same ring, their positions are swapped. If they belong to distinct rings, they also move to each other's ring.
[in] | o | The node to swap with. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inherited |
Count the number of element in the ring.
Warning: This method has a linear response time, avoid using it when possible.