PCL
pcl::XMLElement Class Reference

XML element More...

#include <XML.h>

+ Inheritance diagram for pcl::XMLElement:

Public Types

typedef ReferenceArray< XMLElementchild_element_list
 
typedef XMLNodeList::const_iterator const_iterator
 
typedef XMLNodeList::iterator iterator
 
- Public Types inherited from pcl::XMLNode
typedef XMLNodeType::mask_type node_type
 

Public Member Functions

 XMLElement ()
 
 XMLElement (const String &name, const XMLAttributeList &attributes=XMLAttributeList())
 
 XMLElement (XMLElement &parent, const String &name, const XMLAttributeList &attributes=XMLAttributeList())
 
 XMLElement (const XMLElement &)=delete
 
virtual ~XMLElement ()
 
void AddChildNode (XMLNode *node)
 
void AddChildNodes (XMLNodeList &nodes)
 
XMLAttributeList Attributes () const
 
String AttributeValue (const String &name) const
 
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 ()
 
void DestroyChildNodes ()
 
const_iterator End () const
 
const_iterator end () const
 
const XMLNodeFirst () const
 
bool HasAttribute (const String &name) const
 
bool HasAttributes () const
 
bool HasCDATA () 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 &)=delete
 
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 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 (node_type type)
 
 XMLNode (const XMLNode &x)
 
virtual ~XMLNode ()
 
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
 
- Public Member Functions inherited from pcl::XMLComponent
 XMLComponent ()=default
 
 XMLComponent (const XMLComponent &)=default
 
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 1136 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 1154 of file XML.h.

◆ const_iterator

typedef XMLNodeList::const_iterator pcl::XMLElement::const_iterator

Represents an immutable child node list iterator.

Definition at line 1148 of file XML.h.

◆ iterator

typedef XMLNodeList::iterator pcl::XMLElement::iterator

Represents a mutable child node list iterator.

Definition at line 1143 of file XML.h.

Constructor & Destructor Documentation

◆ XMLElement() [1/4]

pcl::XMLElement::XMLElement ( )
inline

Default constructor. Constructs an uninitialized XMLElement structure.

Definition at line 1159 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 1168 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 1180 of file XML.h.

◆ XMLElement() [4/4]

pcl::XMLElement::XMLElement ( const XMLElement )
delete

Copy constructor. This constructor is disabled because XMLElement represents unique objects.

◆ ~XMLElement()

virtual pcl::XMLElement::~XMLElement ( )
inlinevirtual

Virtual destructor. If this element contains child nodes, all of them will be destroyed recursively.

Definition at line 1204 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 1684 of file XML.h.

◆ 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 1711 of file XML.h.

◆ Attributes()

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

Returns a copy of the list of XML element attributes.

Definition at line 1235 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 1262 of file XML.h.

◆ Begin()

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 1467 of file XML.h.

◆ begin()

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

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

Definition at line 1485 of file XML.h.

◆ ChildCount()

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

Returns the number of child nodes in this XML element.

Definition at line 1419 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 1572 of file XML.h.

References Name().

◆ 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 1605 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 1636 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 1671 of file XML.h.

◆ ClearAttributes()

void pcl::XMLElement::ClearAttributes ( )
inline

Removes all existing attributes in this element.

Definition at line 1357 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 1746 of file XML.h.

◆ End()

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 1476 of file XML.h.

◆ end()

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

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

Definition at line 1493 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 1448 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 1252 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 1243 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 1518 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 1536 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 1502 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 1527 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 1510 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 1428 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 1219 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 1458 of file XML.h.

◆ Name()

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

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

Definition at line 1227 of file XML.h.

Referenced by ChildElements().

◆ 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 1306 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 1338 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 1698 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 1723 of file XML.h.

◆ operator=()

XMLElement& pcl::XMLElement::operator= ( const XMLElement )
delete

Copy assignment. This operator is disabled because XMLElement represents unique objects.

◆ 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 1438 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 1394 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 1761 of file XML.h.

◆ 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 1349 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.

◆ 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 1411 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 1282 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 1294 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 1327 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 1366 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 1378 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: