ITK  5.4.0
Insight Toolkit
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
itk::DOMNode Class Reference

#include <itkDOMNode.h>

Detailed Description

Class to represent a node in a Document Object Model (DOM) tree structure.

A DOM is a structured document representation, in our case parsed from an XML stream (i.e. a file or a string). It is a tree structure in which each node has links to its children nodes and to its parent node (if it is not the root). This class serves as a base node corresponding to an XML tag that only contains attributes (no content for the tag itself).

Note
We reserve the use of the attribute "id" (all combinations of upper and lower case) for uniquely identifying an XML structure among its siblings. That is, we assume that this tag is unique among all siblings in an XML tree structure. If it is not unique, the user may not be able to correctly retrieve a node by function GetChildByID(), or to search for a node using Find() with a query string that is based on "id".
Examples
Examples/IO/XML/DOMFindDemo.cxx.

Definition at line 53 of file itkDOMNode.h.

+ Inheritance diagram for itk::DOMNode:
+ Collaboration diagram for itk::DOMNode:

Public Types

using AttributeItemType = std::pair< const AttributeKeyType, AttributeValueType >
 
using AttributeKeyType = std::string
 
using AttributesListType = std::list< AttributeItemType >
 
using AttributeValueType = std::string
 
using ChildrenListType = std::vector< DOMNode * >
 
using ConstChildrenListType = std::vector< const DOMNode * >
 
using ConstPointer = SmartPointer< const Self >
 
using IdentifierType = int
 
using OffsetType = int
 
using Pointer = SmartPointer< Self >
 
using Self = DOMNode
 
using SizeType = vcl_size_t
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

virtual void AddChild (DOMNode *node, IdentifierType i=0)
 
virtual void AddChildAtBegin (DOMNode *node)
 
virtual void AddChildAtEnd (DOMNode *node)
 
virtual void AddTextChild (const std::string &text, IdentifierType i=0)
 
virtual void AddTextChildAtBegin (const std::string &text)
 
virtual void AddTextChildAtEnd (const std::string &text)
 
virtual void GetAllAttributes (AttributesListType &output, bool keepOriginalOrder=true) const
 
virtual void GetAllChildren (ChildrenListType &output)
 
virtual void GetAllChildren (ConstChildrenListType &output) const
 
virtual std::string GetAttribute (const std::string &key) const
 
virtual void GetChildren (const std::string &tag, ChildrenListType &output)
 
virtual void GetChildren (const std::string &tag, ConstChildrenListType &output) const
 
const char * GetNameOfClass () const override
 
virtual SizeType GetNumberOfChildren () const
 
virtual std::string GetPath () const
 
virtual bool HasAttribute (const std::string &key) const
 
virtual void RemoveAllAttributes ()
 
virtual void RemoveAllAttributesAndChildren ()
 
virtual void RemoveAllChildren ()
 
virtual void RemoveAttribute (const std::string &key)
 
virtual void RemoveChild (IdentifierType i=0)
 
virtual void SetAttribute (const std::string &key, const std::string &value)
 
virtual void SetChild (DOMNode *node, IdentifierType i=0)
 
virtual void SetTextChild (const std::string &text, IdentifierType i=0)
 
virtual bool ShareRoot (const DOMNode *node) const
 
virtual void SetParent (DOMNode *node)
 
DOMNodeGetParent ()
 
const DOMNodeGetParent () const
 
virtual void SetName (const std::string &_arg)
 
virtual const std::string & GetName () const
 
virtual void SetID (const std::string &_arg)
 
virtual const std::string & GetID () const
 
virtual DOMNodeGetChild (IdentifierType i=0)
 
virtual const DOMNodeGetChild (IdentifierType i=0) const
 
virtual DOMNodeGetChild (const std::string &tag, IdentifierType i=0)
 
virtual const DOMNodeGetChild (const std::string &tag, IdentifierType i=0) const
 
virtual DOMNodeGetChildByID (const std::string &value)
 
virtual const DOMNodeGetChildByID (const std::string &value) const
 
virtual DOMNodeGetSibling (OffsetType i)
 
virtual const DOMNodeGetSibling (OffsetType i) const
 
virtual DOMNodeGetRoot ()
 
virtual const DOMNodeGetRoot () const
 
virtual DOMNodeFind (const std::string &path)
 
virtual const DOMNodeFind (const std::string &path) const
 
virtual DOMTextNodeGetTextChild (IdentifierType i=0)
 
virtual const DOMTextNodeGetTextChild (IdentifierType i=0) const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

 DOMNode ()
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Private Types

using AttributesContainer = std::map< AttributeKeyType, AttributeValueType >
 
using ChildrenContainer = std::vector< Pointer >
 
using OrderedAttributesContainer = std::list< AttributeItemType * >
 

Private Attributes

AttributesContainer m_Attributes {}
 
ChildrenContainer m_Children {}
 
std::string m_ID {}
 
std::string m_Name {}
 
OrderedAttributesContainer m_OrderedAttributes {}
 
DOMNodem_Parent { nullptr }
 

Additional Inherited Members

- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Member Typedef Documentation

◆ AttributeItemType

Definition at line 78 of file itkDOMNode.h.

◆ AttributeKeyType

using itk::DOMNode::AttributeKeyType = std::string

An attribute is a pair of <key,value>, both key and value are strings.

Definition at line 75 of file itkDOMNode.h.

◆ AttributesContainer

Internally the attributes are stored in a map.

Definition at line 289 of file itkDOMNode.h.

◆ AttributesListType

Container to return the attributes of a DOM node.

Definition at line 81 of file itkDOMNode.h.

◆ AttributeValueType

using itk::DOMNode::AttributeValueType = std::string

Definition at line 76 of file itkDOMNode.h.

◆ ChildrenContainer

using itk::DOMNode::ChildrenContainer = std::vector<Pointer>
private

Internally the children are stored in a vector.

Definition at line 285 of file itkDOMNode.h.

◆ ChildrenListType

using itk::DOMNode::ChildrenListType = std::vector<DOMNode *>

Container to return all or a subset of the children of a DOM node.

Definition at line 71 of file itkDOMNode.h.

◆ ConstChildrenListType

using itk::DOMNode::ConstChildrenListType = std::vector<const DOMNode *>

Definition at line 72 of file itkDOMNode.h.

◆ ConstPointer

Definition at line 62 of file itkDOMNode.h.

◆ IdentifierType

Definition at line 84 of file itkDOMNode.h.

◆ OffsetType

Definition at line 85 of file itkDOMNode.h.

◆ OrderedAttributesContainer

Container to keep the inserting orders of the attributes.

Definition at line 293 of file itkDOMNode.h.

◆ Pointer

Definition at line 61 of file itkDOMNode.h.

◆ Self

Standard class type aliases.

Definition at line 59 of file itkDOMNode.h.

◆ SizeType

using itk::DOMNode::SizeType = vcl_size_t

Definition at line 83 of file itkDOMNode.h.

◆ Superclass

Definition at line 60 of file itkDOMNode.h.

Constructor & Destructor Documentation

◆ DOMNode()

itk::DOMNode::DOMNode ( )
protected

Member Function Documentation

◆ AddChild()

virtual void itk::DOMNode::AddChild ( DOMNode node,
IdentifierType  i = 0 
)
virtual

Add a child in front of another child (throw exception if not able to add).

◆ AddChildAtBegin()

virtual void itk::DOMNode::AddChildAtBegin ( DOMNode node)
virtual

Add a child in front of the children list (throw exception if not able to add).

◆ AddChildAtEnd()

virtual void itk::DOMNode::AddChildAtEnd ( DOMNode node)
virtual

Add a child at the end of the children list (throw exception if not able to add).

◆ AddTextChild()

virtual void itk::DOMNode::AddTextChild ( const std::string &  text,
IdentifierType  i = 0 
)
virtual

Generate a text node from a string and add/insert it as a child (see AddChild(node,i)).

◆ AddTextChildAtBegin()

virtual void itk::DOMNode::AddTextChildAtBegin ( const std::string &  text)
virtual

Generate a text node from a string and add/insert in front of all children.

◆ AddTextChildAtEnd()

virtual void itk::DOMNode::AddTextChildAtEnd ( const std::string &  text)
virtual

Generate a text node from a string and add/insert at the end of all children.

◆ Find() [1/2]

virtual DOMNode* itk::DOMNode::Find ( const std::string &  path)
virtual

The following function finds a child or sibling or relative using a query string or path. A path or QueryString consists of multiple following items that are separated by '/':

*     -[n]           : an older sibling by distance 1 (when omitted) or n;
*     +[n]           : a younger sibling by distance 1 (when omitted) or n;
*     n              : a child at index n;
*     <tag>[:n]      : a child at index 0 (when omitted) or n after filtering children with a tag name;
*     ![:n]          : a child at index 0 (when omitted) or n within all text children;
*     :<id>          : a child by id;
*     .              : current node;
*     ..             : parent node;
*     /<rpath>       : absolute path (denote apath), search from the root.
* 

The method returns nullptr if queried node does not exist.

◆ Find() [2/2]

virtual const DOMNode* itk::DOMNode::Find ( const std::string &  path) const
virtual

The following function finds a child or sibling or relative using a query string or path. A path or QueryString consists of multiple following items that are separated by '/':

*     -[n]           : an older sibling by distance 1 (when omitted) or n;
*     +[n]           : a younger sibling by distance 1 (when omitted) or n;
*     n              : a child at index n;
*     <tag>[:n]      : a child at index 0 (when omitted) or n after filtering children with a tag name;
*     ![:n]          : a child at index 0 (when omitted) or n within all text children;
*     :<id>          : a child by id;
*     .              : current node;
*     ..             : parent node;
*     /<rpath>       : absolute path (denote apath), search from the root.
* 

The method returns nullptr if queried node does not exist.

◆ GetAllAttributes()

virtual void itk::DOMNode::GetAllAttributes ( AttributesListType output,
bool  keepOriginalOrder = true 
) const
virtual

Return all attributes, in the order of being parsed or added (default), or alphabetic order of the attribute keys (keepOriginalOrder = false).

◆ GetAllChildren() [1/2]

virtual void itk::DOMNode::GetAllChildren ( ChildrenListType output)
virtual

Return all children.

◆ GetAllChildren() [2/2]

virtual void itk::DOMNode::GetAllChildren ( ConstChildrenListType output) const
virtual

Return all children for read-only access.

◆ GetAttribute()

virtual std::string itk::DOMNode::GetAttribute ( const std::string &  key) const
virtual

Retrieve an attribute by key (return an empty string if not found).

◆ GetChild() [1/4]

virtual DOMNode* itk::DOMNode::GetChild ( const std::string &  tag,
IdentifierType  i = 0 
)
virtual

Retrieve a child by tag name and an index (multiple children can have a same tag name, return nullptr if no such child).

◆ GetChild() [2/4]

virtual const DOMNode* itk::DOMNode::GetChild ( const std::string &  tag,
IdentifierType  i = 0 
) const
virtual

Retrieve a child by tag name and an index (multiple children can have a same tag name, return nullptr if no such child).

◆ GetChild() [3/4]

virtual DOMNode* itk::DOMNode::GetChild ( IdentifierType  i = 0)
virtual

Retrieve a child by index (return nullptr if i is out of range).

◆ GetChild() [4/4]

virtual const DOMNode* itk::DOMNode::GetChild ( IdentifierType  i = 0) const
virtual

Retrieve a child by index (return nullptr if i is out of range).

◆ GetChildByID() [1/2]

virtual DOMNode* itk::DOMNode::GetChildByID ( const std::string &  value)
virtual

Retrieve a child by its unique "id" attribute value (return nullptr if not found).

◆ GetChildByID() [2/2]

virtual const DOMNode* itk::DOMNode::GetChildByID ( const std::string &  value) const
virtual

Retrieve a child by its unique "id" attribute value (return nullptr if not found).

◆ GetChildren() [1/2]

virtual void itk::DOMNode::GetChildren ( const std::string &  tag,
ChildrenListType output 
)
virtual

Return all children of a same tag name.

◆ GetChildren() [2/2]

virtual void itk::DOMNode::GetChildren ( const std::string &  tag,
ConstChildrenListType output 
) const
virtual

Return all children of a same tag name for read-only access.

◆ GetID()

virtual const std::string& itk::DOMNode::GetID ( ) const
virtual

Retrieve the special attribute "id" of this node.

◆ GetName()

virtual const std::string& itk::DOMNode::GetName ( ) const
virtual

Retrieve the tag name of this node.

◆ GetNameOfClass()

const char* itk::DOMNode::GetNameOfClass ( ) const
overridevirtual
See also
LightObject::GetNameOfClass()

Reimplemented from itk::Object.

Reimplemented in itk::DOMTextNode.

◆ GetNumberOfChildren()

virtual SizeType itk::DOMNode::GetNumberOfChildren ( ) const
virtual

Get number of children.

◆ GetParent() [1/2]

DOMNode* itk::DOMNode::GetParent ( )

Retrieve the parent node.

◆ GetParent() [2/2]

const DOMNode* itk::DOMNode::GetParent ( ) const

Retrieve the parent node.

◆ GetPath()

virtual std::string itk::DOMNode::GetPath ( ) const
virtual

Return the path of this node within its root, in the form of a query string that uses only indices.

◆ GetRoot() [1/2]

virtual DOMNode* itk::DOMNode::GetRoot ( )
virtual

Return the root node.

◆ GetRoot() [2/2]

virtual const DOMNode* itk::DOMNode::GetRoot ( ) const
virtual

Return the root node.

◆ GetSibling() [1/2]

virtual DOMNode* itk::DOMNode::GetSibling ( OffsetType  i)
virtual

Retrieve an older or younger sibling by distance (return nullptr if no such sibling).

◆ GetSibling() [2/2]

virtual const DOMNode* itk::DOMNode::GetSibling ( OffsetType  i) const
virtual

Retrieve an older or younger sibling by distance (return nullptr if no such sibling).

◆ GetTextChild() [1/2]

virtual DOMTextNode* itk::DOMNode::GetTextChild ( IdentifierType  i = 0)
virtual

Get a child and cast it to a text node (return nullptr if out of range or not a text node).

◆ GetTextChild() [2/2]

virtual const DOMTextNode* itk::DOMNode::GetTextChild ( IdentifierType  i = 0) const
virtual

Get a child and cast it to a text node (return nullptr if out of range or not a text node).

◆ HasAttribute()

virtual bool itk::DOMNode::HasAttribute ( const std::string &  key) const
virtual

Check whether has an attribute.

◆ New()

static Pointer itk::DOMNode::New ( )
static

Method for creation through the object factory.

Examples
Examples/IO/XML/itkParticleSwarmOptimizerDOMWriter.cxx.

◆ RemoveAllAttributes()

virtual void itk::DOMNode::RemoveAllAttributes ( )
virtual

Remove all attributes.

◆ RemoveAllAttributesAndChildren()

virtual void itk::DOMNode::RemoveAllAttributesAndChildren ( )
virtual

Remove all attributes and children.

◆ RemoveAllChildren()

virtual void itk::DOMNode::RemoveAllChildren ( )
virtual

Remove all children.

◆ RemoveAttribute()

virtual void itk::DOMNode::RemoveAttribute ( const std::string &  key)
virtual

Remove an attribute by key (throw exception if not found).

◆ RemoveChild()

virtual void itk::DOMNode::RemoveChild ( IdentifierType  i = 0)
virtual

Remove a child by index (throw exception if not able to remove).

◆ SetAttribute()

virtual void itk::DOMNode::SetAttribute ( const std::string &  key,
const std::string &  value 
)
virtual

Add or replace an attribute.

◆ SetChild()

virtual void itk::DOMNode::SetChild ( DOMNode node,
IdentifierType  i = 0 
)
virtual

Replace a child (throw exception if not able to replace).

◆ SetID()

virtual void itk::DOMNode::SetID ( const std::string &  _arg)
virtual

Retrieve the special attribute "id" of this node.

◆ SetName()

virtual void itk::DOMNode::SetName ( const std::string &  _arg)
virtual

Retrieve the tag name of this node.

Referenced by itk::DOMTextNode::DOMTextNode().

◆ SetParent()

virtual void itk::DOMNode::SetParent ( DOMNode node)
virtual

Retrieve the parent node.

◆ SetTextChild()

virtual void itk::DOMNode::SetTextChild ( const std::string &  text,
IdentifierType  i = 0 
)
virtual

Generate a text node from a string and replace a child with it (see SetChild(node,i).

◆ ShareRoot()

virtual bool itk::DOMNode::ShareRoot ( const DOMNode node) const
virtual

Test whether the input node and this node share the same root.

Member Data Documentation

◆ m_Attributes

AttributesContainer itk::DOMNode::m_Attributes {}
private

Definition at line 290 of file itkDOMNode.h.

◆ m_Children

ChildrenContainer itk::DOMNode::m_Children {}
private

Definition at line 286 of file itkDOMNode.h.

◆ m_ID

std::string itk::DOMNode::m_ID {}
private

The special attribute "id" of this node.

Definition at line 282 of file itkDOMNode.h.

◆ m_Name

std::string itk::DOMNode::m_Name {}
private

The XML tag of this node.

Definition at line 279 of file itkDOMNode.h.

◆ m_OrderedAttributes

OrderedAttributesContainer itk::DOMNode::m_OrderedAttributes {}
private

Definition at line 294 of file itkDOMNode.h.

◆ m_Parent

DOMNode* itk::DOMNode::m_Parent { nullptr }
private

The parent node that this node was placed into.

Definition at line 276 of file itkDOMNode.h.


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