PCL
pcl::XMLElement Class Reference

XML element More...

#include <XML.h>

+ Inheritance diagram for pcl::XMLElement:

Public Types

using child_element_list = ReferenceArray< XMLElement >
 
using const_iterator = XMLNodeList::const_iterator
 
using iterator = XMLNodeList::iterator
 
- Public Types inherited from pcl::XMLNode
using node_type = XMLNodeType::mask_type
 

Public Member Functions

 XMLElement ()
 
 XMLElement (const String &name, const XMLAttributeList &attributes=XMLAttributeList())
 
 XMLElement (const XMLElement &x)
 
 XMLElement (XMLElement &parent, const String &name, const XMLAttributeList &attributes=XMLAttributeList())
 
 ~XMLElement () override
 
void AddChildNode (XMLNode *node)
 
void AddChildNodes (XMLNodeList &nodes)
 
XMLAttributeList Attributes () const
 
String AttributeValue (const String &name) const
 
iterator Begin ()
 
iterator begin ()
 
const_iterator Begin () const
 
const_iterator begin () const
 
int ChildCount () const
 
child_element_list ChildElements (bool recursive=false) const
 
child_element_list ChildElementsByName (const String &name, bool recursive=false) const
 
XMLNodeList ChildNodesByType (XMLNodeTypes types, bool recursive=false) const
 
template<class UP >
XMLNodeList ChildNodesThat (UP u, bool recursive=false) const
 
void ClearAttributes ()
 
XMLNodeClone () const override
 
const_iterator ConstBegin () const
 
const_iterator ConstEnd () const
 
void DestroyChildNodes ()
 
iterator End ()
 
iterator end ()
 
const_iterator End () const
 
const_iterator end () const
 
const XMLNodeFirst () const
 
bool HasAttribute (const String &name) const
 
bool HasAttributes () const
 
bool HasCDATA () const
 
bool HasChildElementWithName (const String &name, bool recursive=false) const
 
template<class UP >
bool HasChildNodeThat (UP u, bool recursive=false) const
 
bool HasComments () const
 
bool HasElements () const
 
bool HasProcessingInstructions () const
 
bool HasText () const
 
bool IsEmpty () const
 
bool IsRootElement () const
 
const XMLNodeLast () const
 
const StringName () const
 
XMLElementoperator<< (const XMLAttribute &attribute)
 
XMLElementoperator<< (const XMLAttributeList &list)
 
XMLElementoperator<< (XMLNode *node)
 
XMLElementoperator<< (XMLNodeList &nodes)
 
XMLElementoperator= (const XMLElement &x)
 
const XMLNodeoperator[] (int i) const
 
void ParseAttributes (const String &text)
 
XMLNodeList ReleaseChildNodes ()
 
void RemoveAttribute (const String &name)
 
void Serialize (IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
 
void SerializeAsHTML (IsoString &text, bool autoFormat, char indentChar, unsigned indentSize, unsigned level) const override
 
void SerializeAttributes (IsoString &text) const
 
void SetAttribute (const String &name, const String &value)
 
void SetAttribute (const XMLAttribute &attribute)
 
void SetAttributes (const XMLAttributeList &list)
 
void SortAttributes ()
 
template<class BP >
void SortAttributes (BP p)
 
String Text () const
 
- Public Member Functions inherited from pcl::XMLNode
 XMLNode (const XMLNode &x)
 
 XMLNode (node_type type)
 
 ~XMLNode () override
 
bool IsChildNode () const
 
bool IsComment () const
 
bool IsElement () const
 
bool IsText () const
 
const XMLNodeLocationLocation () const
 
virtual bool NLAfter (const XMLNode &previous) const
 
node_type NodeType () const
 
XMLNodeoperator= (const XMLNode &x)
 
- Public Member Functions inherited from pcl::XMLComponent
 XMLComponent ()=default
 
 XMLComponent (const XMLComponent &)=default
 
virtual ~XMLComponent ()
 
bool IsTopLevel () const
 
XMLElementParentElement () const
 

Detailed Description

The XMLElement class represents an XML document element:

https://www.w3.org/TR/xml11/#dt-element

Elements are the main data holders in the logical design of XML, following a hierarchical tree structure.

Definition at line 1176 of file XML.h.

Member Typedef Documentation

◆ child_element_list

A list of child XML elements. Implemented as a template instantiation of ReferenceArray<> for the XMLElement class.

Definition at line 1194 of file XML.h.

◆ const_iterator

using pcl::XMLElement::const_iterator = XMLNodeList::const_iterator

Represents an immutable child node list iterator.

Definition at line 1188 of file XML.h.

◆ iterator

using pcl::XMLElement::iterator = XMLNodeList::iterator

Represents a mutable child node list iterator.

Definition at line 1183 of file XML.h.

Constructor & Destructor Documentation

◆ XMLElement() [1/4]

pcl::XMLElement::XMLElement ( )
inline

Default constructor. Constructs an uninitialized XMLElement structure.

Definition at line 1199 of file XML.h.

◆ XMLElement() [2/4]

pcl::XMLElement::XMLElement ( const String name,
const XMLAttributeList attributes = XMLAttributeList() 
)
inline

Constructs an empty XMLElement object with the specified qualified name and attributes.

Definition at line 1208 of file XML.h.

◆ XMLElement() [3/4]

pcl::XMLElement::XMLElement ( XMLElement parent,
const String name,
const XMLAttributeList attributes = XMLAttributeList() 
)
inline

Constructs an empty XMLElement object with the specified qualified name and attributes, as a child node of the specified parent element.

Definition at line 1220 of file XML.h.

◆ XMLElement() [4/4]

pcl::XMLElement::XMLElement ( const XMLElement x)
inline

Copy constructor.

Definition at line 1231 of file XML.h.

References pcl::XMLNode::Clone().

◆ ~XMLElement()

pcl::XMLElement::~XMLElement ( )
inlineoverride

Destroys an XMLElement object. If this element contains child nodes, all of them will be destroyed recursively.

Definition at line 1260 of file XML.h.

Member Function Documentation

◆ AddChildNode()

void pcl::XMLElement::AddChildNode ( XMLNode node)
inline

Appends a child node to this XML element.

The specified node will be owned by this element, which will destroy it automatically (and recursively) upon destruction.

Definition at line 1844 of file XML.h.

References pcl::XMLNode::NodeType(), and pcl::Flags< E >::SetFlag().

◆ AddChildNodes()

void pcl::XMLElement::AddChildNodes ( XMLNodeList nodes)
inline

Appends an ordered sequence of child nodes to this XML element.

After calling this function, all existing nodes in the specified list will be owned by this element, which will destroy them automatically (and recursively) upon destruction.

Definition at line 1871 of file XML.h.

◆ Attributes()

XMLAttributeList pcl::XMLElement::Attributes ( ) const
inline

Returns a copy of the list of XML element attributes.

Definition at line 1291 of file XML.h.

◆ AttributeValue()

String pcl::XMLElement::AttributeValue ( const String name) const
inline

Returns the value of the attribute with the specified qualified name in this element, or an empty string if this element has no such attribute.

Definition at line 1318 of file XML.h.

◆ Begin() [1/2]

iterator pcl::XMLElement::Begin ( )
inline

Returns a mutable iterator located at the beginning of the list of child nodes of this XML element.

Definition at line 1561 of file XML.h.

◆ begin() [1/2]

iterator pcl::XMLElement::begin ( )
inline

STL-compatible iteration. Equivalent to Begin().

Definition at line 1597 of file XML.h.

◆ Begin() [2/2]

const_iterator pcl::XMLElement::Begin ( ) const
inline

Returns an immutable iterator located at the beginning of the list of child nodes of this XML element.

Definition at line 1523 of file XML.h.

◆ begin() [2/2]

const_iterator pcl::XMLElement::begin ( ) const
inline

STL-compatible iteration. Equivalent to Begin() const.

Definition at line 1541 of file XML.h.

◆ ChildCount()

int pcl::XMLElement::ChildCount ( ) const
inline

Returns the number of child nodes in this XML element.

Definition at line 1475 of file XML.h.

◆ ChildElements()

child_element_list pcl::XMLElement::ChildElements ( bool  recursive = false) const
inline

Returns a list with all child elements of this element.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant elements will be returned.

Definition at line 1686 of file XML.h.

◆ ChildElementsByName()

child_element_list pcl::XMLElement::ChildElementsByName ( const String name,
bool  recursive = false 
) const
inline

Returns a list with all child elements of this element with the specified name.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant elements will be returned.

Definition at line 1719 of file XML.h.

◆ ChildNodesByType()

XMLNodeList pcl::XMLElement::ChildNodesByType ( XMLNodeTypes  types,
bool  recursive = false 
) const
inline

Returns a list with all child nodes of this element of the specified types. The types argument can be an ORed combination of XMLNodeType enumerated mask values.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant nodes will be returned.

Definition at line 1773 of file XML.h.

◆ ChildNodesThat()

template<class UP >
XMLNodeList pcl::XMLElement::ChildNodesThat ( UP  u,
bool  recursive = false 
) const
inline

Returns a list with all child nodes of this element that satisfy the specified unary predicate u.

For each child node n in this element, n will be included in the returned list iff u( n ) returns true.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant nodes will be returned.

Definition at line 1808 of file XML.h.

◆ ClearAttributes()

void pcl::XMLElement::ClearAttributes ( )
inline

Removes all existing attributes in this element.

Definition at line 1413 of file XML.h.

◆ Clone()

XMLNode* pcl::XMLElement::Clone ( ) const
inlineoverridevirtual

Returns a dynamically allocated copy of this XML node.

Implements pcl::XMLNode.

Definition at line 1932 of file XML.h.

◆ ConstBegin()

const_iterator pcl::XMLElement::ConstBegin ( ) const
inline

Returns an immutable iterator located at the beginning of the list of child nodes of this XML element.

Definition at line 1579 of file XML.h.

◆ ConstEnd()

const_iterator pcl::XMLElement::ConstEnd ( ) const
inline

Returns an immutable iterator located at the end of the list of child nodes of this XML element.

Definition at line 1588 of file XML.h.

◆ DestroyChildNodes()

void pcl::XMLElement::DestroyChildNodes ( )
inline

Recursively destroys all existing child nodes in this XML element, yielding an empty element.

Definition at line 1906 of file XML.h.

◆ End() [1/2]

iterator pcl::XMLElement::End ( )
inline

Returns a mutable iterator located at the end of the list of child nodes of this XML element.

Definition at line 1570 of file XML.h.

◆ end() [1/2]

iterator pcl::XMLElement::end ( )
inline

STL-compatible iteration. Equivalent to End().

Definition at line 1605 of file XML.h.

◆ End() [2/2]

const_iterator pcl::XMLElement::End ( ) const
inline

Returns an immutable iterator located at the end of the list of child nodes of this XML element.

Definition at line 1532 of file XML.h.

◆ end() [2/2]

const_iterator pcl::XMLElement::end ( ) const
inline

STL-compatible iteration. Equivalent to End() const.

Definition at line 1549 of file XML.h.

◆ First()

const XMLNode& pcl::XMLElement::First ( ) const
inline

Returns a reference to the immutable first child node in this element. No bounds checking is performed: if this element is empty, this function invokes undefined behavior.

Definition at line 1504 of file XML.h.

◆ HasAttribute()

bool pcl::XMLElement::HasAttribute ( const String name) const
inline

Returns true iff this element has an attribute with the specified qualified name.

Definition at line 1308 of file XML.h.

◆ HasAttributes()

bool pcl::XMLElement::HasAttributes ( ) const
inline

Returns true iff this element has one or more attributes defined.

Definition at line 1299 of file XML.h.

◆ HasCDATA()

bool pcl::XMLElement::HasCDATA ( ) const
inline

Returns true iff this element contains one or more child CDATA sections.

Definition at line 1632 of file XML.h.

◆ HasChildElementWithName()

bool pcl::XMLElement::HasChildElementWithName ( const String name,
bool  recursive = false 
) const
inline

Returns true iff this element has at least one child element with the specified name.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant elements will be checked.

Definition at line 1734 of file XML.h.

References HasChildElementWithName(), and Name().

Referenced by HasChildElementWithName().

◆ HasChildNodeThat()

template<class UP >
bool pcl::XMLElement::HasChildNodeThat ( UP  u,
bool  recursive = false 
) const
inline

Returns true iff this element has at least one child node that satisfies the specified unary predicate u.

if recursive is true, this member function performs a recursive search across the entire tree structure rooted at this element. Otherwise only the direct descendant nodes will be checked.

Definition at line 1824 of file XML.h.

◆ HasComments()

bool pcl::XMLElement::HasComments ( ) const
inline

Returns true iff this element contains one or more child comment sections.

Definition at line 1650 of file XML.h.

◆ HasElements()

bool pcl::XMLElement::HasElements ( ) const
inline

Returns true iff this element contains one or more child XML elements.

Definition at line 1616 of file XML.h.

◆ HasProcessingInstructions()

bool pcl::XMLElement::HasProcessingInstructions ( ) const
inline

Returns true iff this element contains one or more child processing instructions.

Definition at line 1641 of file XML.h.

◆ HasText()

bool pcl::XMLElement::HasText ( ) const
inline

Returns true iff this element contains one or more child text blocks.

Definition at line 1624 of file XML.h.

◆ IsEmpty()

bool pcl::XMLElement::IsEmpty ( ) const
inline

Returns true iff this is an empty XML element. An empty element has no child nodes.

Definition at line 1484 of file XML.h.

◆ IsRootElement()

bool pcl::XMLElement::IsRootElement ( ) const
inline

Returns true iff this is a root XML element. A root XML element has no parent element.

Note that this member function can return true in two different situations: when the element has been generated during a document parsing process (in which case this is an actual document root element), and if this object has not been initialized yet (because it has been newly constructed and still has not been associated with an XML document).

Definition at line 1275 of file XML.h.

◆ Last()

const XMLNode& pcl::XMLElement::Last ( ) const
inline

Returns a reference to the immutable last child node in this element. No bounds checking is performed: if this element is empty, this function invokes undefined behavior.

Definition at line 1514 of file XML.h.

◆ Name()

const String& pcl::XMLElement::Name ( ) const
inline

Returns a reference to the (immutable) qualified element name.

Definition at line 1283 of file XML.h.

Referenced by HasChildElementWithName().

◆ operator<<() [1/4]

XMLElement& pcl::XMLElement::operator<< ( const XMLAttribute attribute)
inline

Insertion operator. Returns a reference to this object.

This operator is equivalent to SetAttribute( const XMLAttribute& ).

Definition at line 1362 of file XML.h.

◆ operator<<() [2/4]

XMLElement& pcl::XMLElement::operator<< ( const XMLAttributeList list)
inline

Insertion operator. Returns a reference to this object.

This operator is equivalent to SetAttributes( const XMLAttributeList& ).

Definition at line 1394 of file XML.h.

◆ operator<<() [3/4]

XMLElement& pcl::XMLElement::operator<< ( XMLNode node)
inline

Insertion operator: Appends a child node to this XML element. Returns a reference to this object.

This operator does the same as AddChildNode( node ).

Definition at line 1858 of file XML.h.

◆ operator<<() [4/4]

XMLElement& pcl::XMLElement::operator<< ( XMLNodeList nodes)
inline

Insertion operator: Appends an ordered sequence of child nodes to this XML element. Returns a reference to this object.

This operator does the same as AddChildNodes( nodes ).

Definition at line 1883 of file XML.h.

◆ operator=()

XMLElement& pcl::XMLElement::operator= ( const XMLElement x)
inline

Copy assignment operator. Returns a reference to this object.

Definition at line 1244 of file XML.h.

References pcl::XMLNode::Clone().

◆ operator[]()

const XMLNode& pcl::XMLElement::operator[] ( int  i) const
inline

Returns a reference to the immutable child node at the specified zero-based index i. No bounds checking is performed: if the specified index is invalid this function invokes undefined behavior.

Definition at line 1494 of file XML.h.

◆ ParseAttributes()

void pcl::XMLElement::ParseAttributes ( const String text)
inline

Parses the specified text, encoded as UTF-16, to generate a new list of attributes in this XML element. The previous list of attributes, if any, will be replaced by the newly generated list.

The specified text must be a sequence of zero or more Attribute XML definitions pertaining to a start-tag, as described in the W3C recommendation:

https://www.w3.org/TR/xml11/#NT-STag

Definition at line 1450 of file XML.h.

◆ ReleaseChildNodes()

XMLNodeList pcl::XMLElement::ReleaseChildNodes ( )
inline

Releases the child nodes of this XML element.

This function returns the (possibly empty) list of child nodes in this element and causes this object to forget them. The caller will be responsible for destroying and deallocating all of the returned nodes as appropriate. After calling this member function, this XML element will be empty.

Definition at line 1921 of file XML.h.

References pcl::ReferenceArray< T, A >::Clear().

◆ RemoveAttribute()

void pcl::XMLElement::RemoveAttribute ( const String name)
inline

Removes the attribute with the specified qualified name, if it exists in this element. If this element has no attribute with the specified name, this member function has no effect.

Definition at line 1405 of file XML.h.

◆ Serialize()

void pcl::XMLElement::Serialize ( IsoString text,
bool  autoFormat,
char  indentChar,
unsigned  indentSize,
unsigned  level 
) const
overridevirtual

Recursively serializes this XML element and its contents. Appends the generated XML source code to the specified 8-bit text string, encoded in UTF-8.

See XMLNode::Serialize() for information on function parameters.

Implements pcl::XMLNode.

◆ SerializeAsHTML()

void pcl::XMLElement::SerializeAsHTML ( IsoString text,
bool  autoFormat,
char  indentChar,
unsigned  indentSize,
unsigned  level 
) const
overridevirtual

Recursively serializes this XML element and its contents following a set of rules and restrictions pertaining to HTML. Appends the generated XML source code to the specified 8-bit text string, encoded in UTF-8.

See XMLNode::SerializeAsHTML() for information on HTML serialization. See XMLNode::Serialize() for information on function parameters.

Reimplemented from pcl::XMLNode.

◆ SerializeAttributes()

void pcl::XMLElement::SerializeAttributes ( IsoString text) const
inline

Performs the XML serialization of the attribute list in this element and appends it to the specified text string, encoded in UTF-8.

The generated serialization is a sequence of zero or more Attribute XML definitions pertaining to a start-tag, as described in the W3C recommendation:

https://www.w3.org/TR/xml11/#NT-STag

Definition at line 1467 of file XML.h.

◆ SetAttribute() [1/2]

void pcl::XMLElement::SetAttribute ( const String name,
const String value 
)
inline

Causes this XML element to contain an attribute with the specified qualified name and value.

If an attribute with the same qualified name already exists in this element, then its value will be changed. Otherwise, a new attribute will be created in this element.

This member function ensures that no XML element can have two or more attributes with the same qualified name. This constraint is part of the XML specification:

https://www.w3.org/TR/xml11/#sec-starttags https://www.w3.org/TR/xml-names/#scoping-defaulting

Definition at line 1338 of file XML.h.

◆ SetAttribute() [2/2]

void pcl::XMLElement::SetAttribute ( const XMLAttribute attribute)
inline

Causes this XML element to contain the specified attribute.

See SetAttribute( const String&, const String& ) for more information.

Definition at line 1350 of file XML.h.

◆ SetAttributes()

void pcl::XMLElement::SetAttributes ( const XMLAttributeList list)
inline

Causes this XML element to contain the specified list of attributes.

For each attribute in the specified list, if an attribute with the same qualified name already exists in this element, then its value will be changed. Otherwise, a new attribute will be created in this element.

This member function ensures that no XML element can have two or more attributes with the same qualified name. This constraint is part of the XML specification:

https://www.w3.org/TR/xml11/#sec-starttags https://www.w3.org/TR/xml-names/#scoping-defaulting

Definition at line 1383 of file XML.h.

◆ SortAttributes() [1/2]

void pcl::XMLElement::SortAttributes ( )
inline

Sorts the existing attributes in this element in ascending order by comparing their qualified names.

Definition at line 1422 of file XML.h.

◆ SortAttributes() [2/2]

template<class BP >
void pcl::XMLElement::SortAttributes ( BP  p)
inline

Sorts the existing attributes in this element in ascending order. Ordering of elements is defined such that for any pair a, b of XMLAttribute objects in this element, the binary predicate p(a,b) is true iff a precedes b.

Definition at line 1434 of file XML.h.

◆ Text()

String pcl::XMLElement::Text ( ) const

Returns the text contents of this element, or an empty string if this element has no text child nodes.

If this element has two or more text child nodes, the returned value is the concatenation of all child text nodes.


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