TSDuck Version 3.21-1704 (TSDuck - The MPEG Transport Stream Toolkit)
ts::xml::Element Class Reference

Structured element in an XML document. More...

Inheritance diagram for ts::xml::Element:
Collaboration diagram for ts::xml::Element:

Public Member Functions

 Element (Report &report=(*ts::NullReport::Instance()), size_t line=0, CaseSensitivity attributeCase=CASE_INSENSITIVE)
 Constructor. More...
 
 Element (Node *parent, const UString &name, CaseSensitivity attributeCase=CASE_INSENSITIVE)
 Constructor. More...
 
ElementaddElement (const UString &childName)
 Add a new child element at the end of children. More...
 
TextaddHexaText (const void *data, size_t size)
 Add a new text containing hexadecimal data inside this node. More...
 
TextaddHexaText (const ByteBlock &data)
 Add a new text containing hexadecimal data inside this node. More...
 
TextaddText (const UString &text)
 Add a new text inside this node. More...
 
const Attributeattribute (const UString &attributeName, bool silent=false) const
 Get an attribute. More...
 
size_t childrenCount () const
 Get the number of children. More...
 
virtual void clear () override
 Clear the content of the node. More...
 
UString debug () const
 Build a debug string for the node. More...
 
size_t depth () const
 Get the depth of an XML element. More...
 
const Documentdocument () const
 Get the document into which the node is located. More...
 
Documentdocument ()
 Get the document into which the node is located. More...
 
const ElementfindFirstChild (const UString &name, bool silent=false) const
 Find the first child element by name, case-insensitive. More...
 
ElementfindFirstChild (const UString &name, bool silent=false)
 Find the first child element by name, case-insensitive. More...
 
const NodefirstChild () const
 Get the first child of a node. More...
 
NodefirstChild ()
 Get the first child of a node. More...
 
const ElementfirstChildElement () const
 Get the first child Element of a node. More...
 
ElementfirstChildElement ()
 Get the first child Element of a node. More...
 
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. More...
 
void getAttributesNames (UStringList &names) const
 Get the list of all attribute names. More...
 
void getAttributesNamesInModificationOrder (UStringList &names) const
 Get the list of all attribute names, sorted by modification order. More...
 
bool getBoolAttribute (bool &value, const UString &name, bool required=false, bool defValue=false) const
 Get a boolean attribute of an XML element. More...
 
bool getChildren (ElementVector &children, const UString &name, size_t minCount=0, size_t maxCount=UNLIMITED) const
 Find all children elements by name, case-insensitive. More...
 
bool getDateTimeAttribute (Time &value, const UString &name, bool required=false, const Time &defValue=Time()) const
 Get a date/time attribute of an XML element. More...
 
bool getEnumAttribute (int &value, const Enumeration &definition, const UString &name, bool required=false, int defValue=0) const
 Get an enumeration attribute of an XML element. More...
 
bool getHexaText (ByteBlock &data, size_t minSize=0, size_t maxSize=UNLIMITED) const
 Get and interpret the hexadecimal data inside the element. More...
 
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. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool getIntAttribute (INT &value, const UString &name, bool required=false, INT defValue=0, INT minValue=std::numeric_limits< INT >::min(), INT maxValue=std::numeric_limits< INT >::max()) const
 Get an integer attribute of an XML element. More...
 
template<typename ENUM , typename std::enable_if< std::is_enum< ENUM >::value >::type * = nullptr, typename INT = typename std::underlying_type<ENUM>::type>
bool getIntAttribute (ENUM &value, const UString &name, bool required=false, ENUM defValue=0, INT minValue=0, INT maxValue=std::numeric_limits< INT >::max()) const
 Get an integer attribute of an XML element in an enum type. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool getIntEnumAttribute (INT &value, const Enumeration &definition, const UString &name, bool required=false, INT defValue=INT(0)) const
 Get an enumeration attribute of an XML element. More...
 
bool getIPAttribute (IPAddress &value, const UString &name, bool required=false, const IPAddress &defValue=IPAddress()) const
 Get an IPv4 address attribute of an XML element in "x.x.x.x" format or host name. More...
 
bool getIPv6Attribute (IPv6Address &value, const UString &name, bool required=false, const IPv6Address &defValue=IPv6Address()) const
 Get an IPv6 address attribute of an XML element. More...
 
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. More...
 
bool getOptionalAttribute (Variable< UString > &value, const UString &name, size_t minSize=0, size_t maxSize=UNLIMITED) const
 Get an optional string attribute of an XML element. More...
 
bool getOptionalBoolAttribute (Variable< bool > &value, const UString &name) const
 Get an optional boolean attribute of an XML element. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool getOptionalIntAttribute (Variable< INT > &value, const UString &name, INT minValue=std::numeric_limits< INT >::min(), INT maxValue=std::numeric_limits< INT >::max()) const
 Get an optional integer attribute of an XML element. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool getOptionalIntEnumAttribute (Variable< INT > &value, const Enumeration &definition, const UString &name) const
 Get an optional enumeration attribute of an XML element. More...
 
bool getText (UString &data, bool trim=false, size_t minSize=0, size_t maxSize=UNLIMITED) const
 Get text inside an element. More...
 
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. More...
 
bool getTimeAttribute (Second &value, const UString &name, bool required=false, Second defValue=0) const
 Get a time attribute of an XML element in "hh:mm:ss" format. More...
 
bool getVariableAttribute (Variable< 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. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool getVariableIntAttribute (Variable< INT > &value, const UString &name, bool required=false, INT defValue=0, INT minValue=std::numeric_limits< INT >::min(), INT maxValue=std::numeric_limits< INT >::max()) const
 Get an optional integer attribute of an XML element. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool getVariableIntEnumAttribute (Variable< INT > &value, const Enumeration &definition, const UString &name, bool required=false, INT defValue=INT(0)) const
 Get an optional enumeration attribute of an XML element. More...
 
bool hasAttribute (const UString &attributeName) const
 Check if an attribute exists in the element. More...
 
bool hasChildren () const
 Check if the node has children. More...
 
bool haveSameName (const Element *other) const
 Check if two XML elements have the same name, case-insensitive. More...
 
const NodelastChild () const
 Get the last child. More...
 
NodelastChild ()
 Get the last child. More...
 
size_t lineNumber () const
 Get the line number in input document. More...
 
const UStringname () const
 Get the element name. More...
 
const NodenextSibling () const
 Get the next sibling node. More...
 
NodenextSibling ()
 Get the next sibling node. More...
 
const ElementnextSiblingElement () const
 Find the next sibling element. More...
 
ElementnextSiblingElement ()
 Find the next sibling element. More...
 
const Nodeparent () const
 Get the parent's node. More...
 
Nodeparent ()
 Get the parent's node. More...
 
const NodepreviousSibling () const
 Get the previous sibling node. More...
 
NodepreviousSibling ()
 Get the previous sibling node. More...
 
virtual void print (TextFormatter &output, bool keepNodeOpen=false) const override
 Format the node for an output XML document. More...
 
virtual void printClose (TextFormatter &output, size_t levels=std::numeric_limits< size_t >::max()) const override
 Print the closing tags for the node. More...
 
virtual void reparent (Node *newParent, bool last=true)
 Attach the node to a new parent. More...
 
Reportreport () const
 Get a reference to the report object for the XML node. More...
 
bool ringAlone () const
 Check if the node is alone in its own ring. More...
 
void ringInsertAfter (RingNode *o)
 Insert this object in a ring after the specified node. More...
 
void ringInsertBefore (RingNode *o)
 Insert this object in a ring before the specified node. More...
 
template<typename T >
T * ringNext ()
 Get the next node in the ring. More...
 
template<typename T >
const T * ringNext () const
 Get the next node in the ring. More...
 
template<typename T >
T * ringPrevious ()
 Get the previous node in the ring. More...
 
template<typename T >
const T * ringPrevious () const
 Get the previous node in the ring. More...
 
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. More...
 
void ringSwap (RingNode *o)
 Swap this object and another one in their rings. More...
 
void setAttribute (const UString &name, const UString &value, bool onlyIfNotEmpty=false)
 Set an attribute. More...
 
void setBoolAttribute (const UString &name, bool value)
 Set a bool attribute to a node. More...
 
void setDateTimeAttribute (const UString &name, const Time &value)
 Set a date/time attribute of an XML element. More...
 
void setEnumAttribute (const Enumeration &definition, const UString &name, int value)
 Set an enumeration attribute of a node. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void setIntAttribute (const UString &name, INT value, bool hexa=false)
 Set an attribute with an integer value to a node. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void setIntEnumAttribute (const Enumeration &definition, const UString &name, INT value)
 Set an enumeration attribute of a node. More...
 
void setIPAttribute (const UString &name, const IPAddress &value)
 Set an IPv4 address attribute of an XML element in "x.x.x.x" format. More...
 
void setIPv6Attribute (const UString &name, const IPv6Address &value)
 Set an IPv6 address attribute of an XML element. More...
 
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. More...
 
void setOptionalBoolAttribute (const UString &name, const Variable< bool > &value)
 Set an optional bool attribute to a node. More...
 
template<typename ENUM , typename std::enable_if< std::is_enum< ENUM >::value >::type * = nullptr>
void setOptionalEnumAttribute (const Enumeration &definition, const UString &name, const Variable< ENUM > &value)
 Set an optional attribute with an enumeration attribute to a node. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void setOptionalIntAttribute (const UString &name, const Variable< INT > &value, bool hexa=false)
 Set an optional attribute with an integer value to a node. More...
 
void setReportPrefix (const UString &prefix)
 Set the prefix to display on report lines. More...
 
void setTimeAttribute (const UString &name, Second value)
 Set a time attribute of an XML element in "hh:mm:ss" format. More...
 
void setValue (const UString &value)
 Set the value of the node. More...
 
virtual bool stickyOutput () const
 Check if the text shall be stuck to other elements in XML output. More...
 
UString text (bool trim=false) const
 Get text inside an element. More...
 
virtual const Tweakstweaks () const
 Get a constant reference to the current XML parsing and formatting tweaks for this node. More...
 
virtual UString typeName () const override
 Return a node type name, mainly for debug purpose. More...
 
const UStringvalue () const
 Get the value of the node. More...
 

Protected Member Functions

NodeidentifyNextNode (TextParser &parser)
 Identify the next token in the document. More...
 
virtual bool parseChildren (TextParser &parser)
 Parse children nodes and add them to the node. More...
 
virtual bool parseNode (TextParser &parser, const Node *parent) override
 Parse the node. More...
 

Protected Attributes

ReportWithPrefix _report
 Where to report errors.
 
UString _value
 Value of the node, depend on the node type.
 

Detailed Description

Structured element in an XML document.

Constructor & Destructor Documentation

◆ Element() [1/2]

ts::xml::Element::Element ( Report report = (*ts::NullReport::Instance()),
size_t  line = 0,
CaseSensitivity  attributeCase = CASE_INSENSITIVE 
)
explicit

Constructor.

Parameters
[in,out]reportWhere to report errors.
[in]lineLine number in input document.
[in]attributeCaseState if attribute names are stored with case sensitivity.

◆ Element() [2/2]

ts::xml::Element::Element ( Node parent,
const UString name,
CaseSensitivity  attributeCase = CASE_INSENSITIVE 
)

Constructor.

Parameters
[in,out]parentThe parent into which the element is added.
[in]nameName of the element.
[in]attributeCaseState if attribute names are stored wit case sensitivity.

Member Function Documentation

◆ name()

const UString& ts::xml::Element::name ( ) const
inline

Get the element name.

This is the same as the node value.

Returns
A constant reference to the element name.

◆ haveSameName()

bool ts::xml::Element::haveSameName ( const Element other) const
inline

Check if two XML elements have the same name, case-insensitive.

Parameters
[in]otherAnother XML element.
Returns
True is this object and other have identical names.

◆ findFirstChild() [1/2]

const Element* ts::xml::Element::findFirstChild ( const UString name,
bool  silent = false 
) const
inline

Find the first child element by name, case-insensitive.

Parameters
[in]nameName of the child element to search. If empty, get the first element.
[in]silentIf true, do not report error.
Returns
Child element address or zero if not found.

◆ findFirstChild() [2/2]

Element* ts::xml::Element::findFirstChild ( const UString name,
bool  silent = false 
)

Find the first child element by name, case-insensitive.

Parameters
[in]nameName of the child element to search. If empty, get the first element.
[in]silentIf true, do not report error.
Returns
Child element address or zero if not found.

◆ getChildren()

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.

Parameters
[out]childrenReturned vector of all children.
[in]nameName of the child element to search.
[in]minCountMinimum required number of elements of that name.
[in]maxCountMaximum allowed number of elements of that name.
Returns
True on success, false on error.

◆ getTextChild()

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.

Parameters
[out]dataThe content of the text in the child element.
[in]nameName of the child element to search.
[in]trimIf true, remove leading and trailing spaces.
[in]requiredIf true, generate an error if the child element is not found.
[in]defValueDefault value to return if the child element is not present.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ getText()

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.

Parameters
[out]dataThe content of the text children.
[in]trimIf true, remove leading and trailing spaces.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ text()

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.

Parameters
[in]trimIf true, remove leading and trailing spaces.
Returns
The content of the text children, empty if non-existent.

◆ getHexaTextChild()

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.

Parameters
[out]dataThe content of the text in the child element.
[in]nameName of the child element to search.
[in]requiredIf true, generate an error if the child element is not found.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ getHexaText()

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.

Parameters
[out]dataBuffer receiving the decoded hexadecimal data.
[in]minSizeMinimum size of the returned data.
[in]maxSizeMaximum size of the returned data.
Returns
True on success, false on error.

◆ addElement()

Element* ts::xml::Element::addElement ( const UString childName)

Add a new child element at the end of children.

Parameters
[in]childNameName of new child element to create.
Returns
New child element or null on error.

◆ addText()

Text* ts::xml::Element::addText ( const UString text)

Add a new text inside this node.

Parameters
[in]textText string to add.
Returns
New child element or null on error.

◆ addHexaText() [1/2]

Text* ts::xml::Element::addHexaText ( const void *  data,
size_t  size 
)

Add a new text containing hexadecimal data inside this node.

Parameters
[in]dataAddress of binary data.
[in]sizeSize in bytes of binary data.
Returns
New child element or null on error.

◆ addHexaText() [2/2]

Text* ts::xml::Element::addHexaText ( const ByteBlock data)
inline

Add a new text containing hexadecimal data inside this node.

Parameters
[in]dataBinary data.
Returns
New child element or null on error.

◆ hasAttribute()

bool ts::xml::Element::hasAttribute ( const UString attributeName) const

Check if an attribute exists in the element.

Parameters
[in]attributeNameAttribute name.
Returns
True if the attribute exists.

◆ attribute()

const Attribute& ts::xml::Element::attribute ( const UString attributeName,
bool  silent = false 
) const

Get an attribute.

Parameters
[in]attributeNameAttribute name.
[in]silentIf true, do not report error.
Returns
A constant reference to an attribute. If the argument does not exist, the referenced object is marked invalid. The reference is valid as long as the Element object is not modified.

◆ setAttribute()

void ts::xml::Element::setAttribute ( const UString name,
const UString value,
bool  onlyIfNotEmpty = false 
)

Set an attribute.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.
[in]onlyIfNotEmptyWhen true, do not insert the attribute if value is empty.

◆ setBoolAttribute()

void ts::xml::Element::setBoolAttribute ( const UString name,
bool  value 
)
inline

Set a bool attribute to a node.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setOptionalBoolAttribute()

void ts::xml::Element::setOptionalBoolAttribute ( const UString name,
const Variable< bool > &  value 
)
inline

Set an optional bool attribute to a node.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setIntAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::xml::Element::setIntAttribute ( const UString name,
INT  value,
bool  hexa = false 
)
inline

Set an attribute with an integer value to a node.

Template Parameters
INTAn integer type.
Parameters
[in]nameAttribute name.
[in]valueAttribute value.
[in]hexaIf true, use an hexadecimal representation (0x...).

◆ setOptionalIntAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::xml::Element::setOptionalIntAttribute ( const UString name,
const Variable< INT > &  value,
bool  hexa = false 
)
inline

Set an optional attribute with an integer value to a node.

Template Parameters
INTAn integer type.
Parameters
[in]nameAttribute name.
[in]valueAttribute optional value. If the variable is not set, no attribute is set.
[in]hexaIf true, use an hexadecimal representation (0x...).

◆ setEnumAttribute()

void ts::xml::Element::setEnumAttribute ( const Enumeration definition,
const UString name,
int  value 
)
inline

Set an enumeration attribute of a node.

Parameters
[in]definitionThe definition of enumeration values.
[in]nameAttribute name.
[in]valueAttribute value.

◆ setOptionalEnumAttribute()

template<typename ENUM , typename std::enable_if< std::is_enum< ENUM >::value >::type * = nullptr>
void ts::xml::Element::setOptionalEnumAttribute ( const Enumeration definition,
const UString name,
const Variable< ENUM > &  value 
)
inline

Set an optional attribute with an enumeration attribute to a node.

Template Parameters
ENUMAn enum type.
Parameters
[in]definitionThe definition of enumeration values.
[in]nameAttribute name.
[in]valueAttribute optional value. If the variable is not set, no attribute is set.

◆ setIntEnumAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::xml::Element::setIntEnumAttribute ( const Enumeration definition,
const UString name,
INT  value 
)
inline

Set an enumeration attribute of a node.

Template Parameters
INTAn integer type.
Parameters
[in]definitionThe definition of enumeration values.
[in]nameAttribute name.
[in]valueAttribute value.

◆ setDateTimeAttribute()

void ts::xml::Element::setDateTimeAttribute ( const UString name,
const Time value 
)
inline

Set a date/time attribute of an XML element.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setTimeAttribute()

void ts::xml::Element::setTimeAttribute ( const UString name,
Second  value 
)
inline

Set a time attribute of an XML element in "hh:mm:ss" format.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setIPAttribute()

void ts::xml::Element::setIPAttribute ( const UString name,
const IPAddress value 
)
inline

Set an IPv4 address attribute of an XML element in "x.x.x.x" format.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setIPv6Attribute()

void ts::xml::Element::setIPv6Attribute ( const UString name,
const IPv6Address value 
)
inline

Set an IPv6 address attribute of an XML element.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ setMACAttribute()

void ts::xml::Element::setMACAttribute ( const UString name,
const MACAddress value 
)
inline

Set a MAC address attribute of an XML element in "x:x:x:x:x:x" format.

Parameters
[in]nameAttribute name.
[in]valueAttribute value.

◆ getAttribute()

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.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ getOptionalAttribute()

bool ts::xml::Element::getOptionalAttribute ( Variable< UString > &  value,
const UString name,
size_t  minSize = 0,
size_t  maxSize = UNLIMITED 
) const

Get an optional string attribute of an XML element.

Parameters
[out]valueReturned value of the attribute. If the attribute is not present, the variable is reset.
[in]nameName of the attribute.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ getVariableAttribute()

bool ts::xml::Element::getVariableAttribute ( Variable< UString > &  value,
const UString name,
bool  required = false,
const UString defValue = UString(),
size_t  minSize = 0,
size_t  maxSize = UNLIMITED 
) const
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 Variable is unset. With getVariableAttribute(), if the attribute is missing, the Variable is set with the default value.

Parameters
[out]valueReturned value of the attribute. If the attribute is not present, the variable is reset.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
[in]minSizeMinimum allowed size for the value string.
[in]maxSizeMaximum allowed size for the value string.
Returns
True on success, false on error.

◆ getBoolAttribute()

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.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getOptionalBoolAttribute()

bool ts::xml::Element::getOptionalBoolAttribute ( Variable< bool > &  value,
const UString name 
) const

Get an optional boolean attribute of an XML element.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
Returns
True on success, false on error.

◆ getIntAttribute() [1/2]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool ts::xml::Element::getIntAttribute ( INT value,
const UString name,
bool  required = false,
INT  defValue = 0,
INT  minValue = std::numeric_limits< INT >::min(),
INT  maxValue = std::numeric_limits< INT >::max() 
) const

Get an integer attribute of an XML element.

Template Parameters
INTAn integer type.
Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
[in]minValueMinimum allowed value for the attribute.
[in]maxValueMaximum allowed value for the attribute.
Returns
True on success, false on error.

◆ getIntAttribute() [2/2]

template<typename ENUM , typename std::enable_if< std::is_enum< ENUM >::value >::type * = nullptr, typename INT = typename std::underlying_type<ENUM>::type>
bool ts::xml::Element::getIntAttribute ( ENUM &  value,
const UString name,
bool  required = false,
ENUM  defValue = 0,
INT  minValue = 0,
INT  maxValue = std::numeric_limits< INT >::max() 
) const

Get an integer attribute of an XML element in an enum type.

Template Parameters
ENUMAn enumeration type.
Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
[in]minValueMinimum allowed value for the attribute.
[in]maxValueMaximum allowed value for the attribute.
Returns
True on success, false on error.

◆ getOptionalIntAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool ts::xml::Element::getOptionalIntAttribute ( Variable< INT > &  value,
const UString name,
INT  minValue = std::numeric_limits< INT >::min(),
INT  maxValue = std::numeric_limits< INT >::max() 
) const

Get an optional integer attribute of an XML element.

Template Parameters
INTAn integer type.
Parameters
[out]valueReturned value of the attribute. If the attribute is not present, the variable is reset.
[in]nameName of the attribute.
[in]minValueMinimum allowed value for the attribute.
[in]maxValueMaximum allowed value for the attribute.
Returns
True on success, false on error.

◆ getVariableIntAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool ts::xml::Element::getVariableIntAttribute ( Variable< INT > &  value,
const UString name,
bool  required = false,
INT  defValue = 0,
INT  minValue = std::numeric_limits<INT>::min(),
INT  maxValue = std::numeric_limits<INT>::max() 
) const
inline

Get an optional integer attribute of an XML element.

getVariableIntAttribute() is different from getOptionalIntAttribute() in the result. With getOptionalIntAttribute(), if the attribute is missing, the Variable is unset. With getVariableIntAttribute(), if the attribute is missing, the Variable is set with the default value.

Template Parameters
INTAn integer type.
Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
[in]minValueMinimum allowed value for the attribute.
[in]maxValueMaximum allowed value for the attribute.
Returns
True on success, false on error.

◆ getEnumAttribute()

bool ts::xml::Element::getEnumAttribute ( int &  value,
const Enumeration definition,
const UString name,
bool  required = false,
int  defValue = 0 
) const

Get an enumeration attribute of an XML element.

Integer literals and integer values are accepted in the attribute.

Parameters
[out]valueReturned value of the attribute.
[in]definitionThe definition of enumeration values.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getIntEnumAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool ts::xml::Element::getIntEnumAttribute ( INT value,
const Enumeration definition,
const UString name,
bool  required = false,
INT  defValue = INT(0) 
) const

Get an enumeration attribute of an XML element.

Integer literals and integer values are accepted in the attribute.

Template Parameters
INTAn integer or enum type.
Parameters
[out]valueReturned value of the attribute.
[in]definitionThe definition of enumeration values.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getOptionalIntEnumAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool ts::xml::Element::getOptionalIntEnumAttribute ( Variable< 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.

Template Parameters
INTAn integer or enum type.
Parameters
[out]valueReturned value of the attribute. If the attribute is not present, the variable is reset.
[in]definitionThe definition of enumeration values.
[in]nameName of the attribute.
Returns
True on success, false on error.

◆ getVariableIntEnumAttribute()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value||std::is_enum< INT >::value >::type * = nullptr>
bool ts::xml::Element::getVariableIntEnumAttribute ( Variable< INT > &  value,
const Enumeration definition,
const UString name,
bool  required = false,
INT  defValue = INT(0) 
) const
inline

Get an optional enumeration attribute of an XML element.

Integer literals and integer values are accepted in the attribute. getVariableIntEnumAttribute() is different from getOptionalIntEnumAttribute() in the result. With getOptionalIntEnumAttribute(), if the attribute is missing, the Variable is unset. With getVariableIntEnumAttribute(), if the attribute is missing, the Variable is set with the default value.

Template Parameters
INTAn integer or enum type.
Parameters
[out]valueReturned value of the attribute.
[in]definitionThe definition of enumeration values.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getDateTimeAttribute()

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.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getTimeAttribute()

bool ts::xml::Element::getTimeAttribute ( Second value,
const UString name,
bool  required = false,
Second  defValue = 0 
) const

Get a time attribute of an XML element in "hh:mm:ss" format.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getIPAttribute()

bool ts::xml::Element::getIPAttribute ( IPAddress value,
const UString name,
bool  required = false,
const IPAddress defValue = IPAddress() 
) const

Get an IPv4 address attribute of an XML element in "x.x.x.x" format or host name.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getIPv6Attribute()

bool ts::xml::Element::getIPv6Attribute ( IPv6Address value,
const UString name,
bool  required = false,
const IPv6Address defValue = IPv6Address() 
) const

Get an IPv6 address attribute of an XML element.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getMACAttribute()

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.

Parameters
[out]valueReturned value of the attribute.
[in]nameName of the attribute.
[in]requiredIf true, generate an error if the attribute is not found.
[in]defValueDefault value to return if the attribute is not present.
Returns
True on success, false on error.

◆ getAttributesNames()

void ts::xml::Element::getAttributesNames ( UStringList names) const

Get the list of all attribute names.

Parameters
[out]namesReturned list of all attribute names.

◆ getAttributesNamesInModificationOrder()

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().

Parameters
[out]namesReturned list of all attribute names.

◆ clear()

virtual void ts::xml::Element::clear ( )
overridevirtual

Clear the content of the node.

The node becomes empty but remains attached to its parent.

Reimplemented from ts::xml::Node.

◆ typeName()

virtual UString ts::xml::Element::typeName ( ) const
overridevirtual

Return a node type name, mainly for debug purpose.

Returns
Node type name.

Implements ts::xml::Node.

◆ print()

virtual void ts::xml::Element::print ( TextFormatter output,
bool  keepNodeOpen = false 
) const
overridevirtual

Format the node for an output XML document.

Parameters
[in,out]outputThe output object to format the XML document.
[in]keepNodeOpenIf true, keep the node open so that children may be printed later.

Implements ts::xml::Node.

◆ printClose()

virtual void ts::xml::Element::printClose ( TextFormatter output,
size_t  levels = std::numeric_limits< size_t >::max() 
) const
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.

Parameters
[in,out]outputThe output object to format the XML document.
[in]levelsNumber of levels to close. By default, close the complete document. If zero, no output is produced.

Reimplemented from ts::xml::Node.

◆ parseNode()

virtual bool ts::xml::Element::parseNode ( TextParser parser,
const Node parent 
)
overrideprotectedvirtual

Parse the node.

Parameters
[in,out]parserThe 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]parentCandidate parent node, for information only, do not modify. Can be null.
Returns
True on success, false on error.

Implements ts::xml::Node.

◆ lineNumber()

size_t ts::xml::Node::lineNumber ( ) const
inlineinherited

Get the line number in input document.

Returns
The line number in input document, zero if the node was built programmatically.

◆ reparent()

virtual void ts::xml::Node::reparent ( Node newParent,
bool  last = true 
)
virtualinherited

Attach the node to a new parent.

The node is first detached from its previous parent.

Parameters
[in,out]newParentNew 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]lastIf true, the child is added at the end of the list of children. If false, it is added at the beginning.

◆ parent() [1/2]

const Node* ts::xml::Node::parent ( ) const
inlineinherited

Get the parent's node.

Returns
The parent's node or zero if this is a top-level document.

◆ parent() [2/2]

Node* ts::xml::Node::parent ( )
inlineinherited

Get the parent's node.

Returns
The parent's node or zero if this is a top-level document.

◆ document() [1/2]

const Document* ts::xml::Node::document ( ) const
inlineinherited

Get the document into which the node is located.

Returns
The node's document or zero if there is no document.

◆ document() [2/2]

Document* ts::xml::Node::document ( )
inherited

Get the document into which the node is located.

Returns
The node's document or zero if there is no document.

◆ tweaks()

virtual const Tweaks& ts::xml::Node::tweaks ( ) const
virtualinherited

Get a constant reference to the current XML parsing and formatting tweaks for this node.

Returns
A constant reference to the XML tweaks to apply. When the node is part of a document, get the global tweaks of the document. Otherwise, get the default tweaks.

Reimplemented in ts::xml::Document.

◆ depth()

size_t ts::xml::Node::depth ( ) const
inherited

Get the depth of an XML element.

Returns
The depth of the element, ie. the number of ancestors.

◆ hasChildren()

bool ts::xml::Node::hasChildren ( ) const
inlineinherited

Check if the node has children.

Returns
True if the node has children.

◆ childrenCount()

size_t ts::xml::Node::childrenCount ( ) const
inlineinherited

Get the number of children.

Returns
The number of children.

◆ firstChild() [1/2]

const Node* ts::xml::Node::firstChild ( ) const
inlineinherited

Get the first child of a node.

Returns
The first child of the node or zero if there is no children.

◆ firstChild() [2/2]

Node* ts::xml::Node::firstChild ( )
inlineinherited

Get the first child of a node.

Returns
The first child of the node or zero if there is no children.

◆ lastChild() [1/2]

const Node* ts::xml::Node::lastChild ( ) const
inlineinherited

Get the last child.

Returns
The last child or zero if there is none.

◆ lastChild() [2/2]

Node* ts::xml::Node::lastChild ( )
inlineinherited

Get the last child.

Returns
The last child or nullptr if there is none.

◆ nextSibling() [1/2]

const Node* ts::xml::Node::nextSibling ( ) const
inlineinherited

Get the next sibling node.

Returns
The next sibling node or zero if the node is the last child.

◆ nextSibling() [2/2]

Node* ts::xml::Node::nextSibling ( )
inherited

Get the next sibling node.

Returns
The next sibling node or zero if the node is the last child.

◆ previousSibling() [1/2]

const Node* ts::xml::Node::previousSibling ( ) const
inlineinherited

Get the previous sibling node.

Returns
The previous sibling node or zero if the node is the first child.

◆ previousSibling() [2/2]

Node* ts::xml::Node::previousSibling ( )
inherited

Get the previous sibling node.

Returns
The previous sibling node or zero if the node is the first child.

◆ firstChildElement() [1/2]

const Element* ts::xml::Node::firstChildElement ( ) const
inlineinherited

Get the first child Element of a node.

Returns
The first child Element of the node or zero if there is no child Element.

◆ firstChildElement() [2/2]

Element* ts::xml::Node::firstChildElement ( )
inherited

Get the first child Element of a node.

Returns
The first child Element of the node or zero if there is no child Element.

◆ nextSiblingElement() [1/2]

const Element* ts::xml::Node::nextSiblingElement ( ) const
inlineinherited

Find the next sibling element.

Returns
Element address or zero if not found.

◆ nextSiblingElement() [2/2]

Element* ts::xml::Node::nextSiblingElement ( )
inherited

Find the next sibling element.

Returns
Element address or zero if not found.

◆ value()

const UString& ts::xml::Node::value ( ) const
inlineinherited

Get the value of the node.

The semantic of the value depends on the node subclass:

  • Comment: Content of the comment, without "<!--" and "-->".
  • Declaration: Content of the declaration, without "<?" and "?>".
  • Document: Empty.
  • Element: Name of the element.
  • Text: Text content of the element, including spaces and new-lines.
  • Unknown: Content of the tag, probably an uninterpreted DTD.
Returns
A constant reference to the node value, as a string.

◆ setValue()

void ts::xml::Node::setValue ( const UString value)
inlineinherited

Set the value of the node.

Parameters
[in]valueNew value to set.
See also
value()

◆ setReportPrefix()

void ts::xml::Node::setReportPrefix ( const UString prefix)
inlineinherited

Set the prefix to display on report lines.

Parameters
[in]prefixThe prefix to prepend to all messages.

◆ stickyOutput()

virtual bool ts::xml::Node::stickyOutput ( ) const
virtualinherited

Check if the text shall be stuck to other elements in XML output.

Returns
True if the text shall be stuck to other elements. False by default.

Reimplemented in ts::xml::Text.

◆ debug()

UString ts::xml::Node::debug ( ) const
inherited

Build a debug string for the node.

Returns
A debug string for the node.

◆ report()

Report& ts::xml::Node::report ( ) const
inlineinherited

Get a reference to the report object for the XML node.

Returns
A reference to the report object for the XML node.

◆ identifyNextNode()

Node* ts::xml::Node::identifyNextNode ( TextParser parser)
protectedinherited

Identify the next token in the document.

Parameters
[in,out]parserThe document parser.
Returns
A new node or zero either at end of document or before a "</" sequence. The returned node, when not zero, is not yet linked to its parent and siblings. When the returned node is not zero, the parser is located after the tag which identified the node ("<?", "<!--", etc.)

◆ parseChildren()

virtual bool ts::xml::Node::parseChildren ( TextParser parser)
protectedvirtualinherited

Parse children nodes and add them to the node.

Stop either at end of document or before a "</" sequence or on error.

Parameters
[in,out]parserThe document parser.
Returns
True on success, false on error.

◆ ringAlone()

bool ts::RingNode::ringAlone ( ) const
inlineinherited

Check if the node is alone in its own ring.

Returns
True if the node is alone in its own ring.

◆ ringInsertAfter()

void ts::RingNode::ringInsertAfter ( RingNode o)
inherited

Insert this object in a ring after the specified node.

Parameters
[in]oA node of a ring. This object is inserted after o in the ring.

◆ ringInsertBefore()

void ts::RingNode::ringInsertBefore ( RingNode o)
inherited

Insert this object in a ring before the specified node.

Parameters
[in]oA node of a ring. This object is inserted before o in the ring.

◆ ringSwap()

void ts::RingNode::ringSwap ( RingNode o)
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.

Parameters
[in]oThe node to swap with.

◆ ringNext() [1/2]

template<typename T >
T* ts::RingNode::ringNext ( )
inlineinherited

Get the next node in the ring.

Template Parameters
TA superclass of RingNode, the expected type of the next object in the ring.
Returns
Address of the next node in the ring or zero if the next node is not a subclass of T.

◆ ringNext() [2/2]

template<typename T >
const T* ts::RingNode::ringNext ( ) const
inlineinherited

Get the next node in the ring.

Template Parameters
TA superclass of RingNode, the expected type of the next object in the ring.
Returns
Address of the next node in the ring or zero if the next node is not a subclass of T.

◆ ringPrevious() [1/2]

template<typename T >
T* ts::RingNode::ringPrevious ( )
inlineinherited

Get the previous node in the ring.

Template Parameters
TA superclass of RingNode, the expected type of the previous object in the ring.
Returns
Address of the previous node in the ring or zero if the previous node is not a subclass of T.

◆ ringPrevious() [2/2]

template<typename T >
const T* ts::RingNode::ringPrevious ( ) const
inlineinherited

Get the previous node in the ring.

Template Parameters
TA superclass of RingNode, the expected type of the previous object in the ring.
Returns
Address of the previous node in the ring or zero if the previous node is not a subclass of T.

◆ ringSize()

size_t ts::RingNode::ringSize ( ) const
inherited

Count the number of element in the ring.

Warning: This method has a linear response time, avoid using it when possible.

Returns
The number of nodes in the ring.

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