Model Railroad System 2.2.2
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SimpleDOMElement Class Reference

A simple DOM element coded in Tcl using SNIT. More...

Public Member Functions

 SimpleDOMElement (name,...)
 The constructor. More...
 
 children ()
 Method to return the elements children. More...
 
 addchild (childnode)
 Method to add a child node. More...
 
 length ()
 Method to return the number of children. More...
 
 data ()
 Method to return the element's data. More...
 
 setdata (d)
 Method to set the element's data. More...
 
 display (fp="stdout", indent="")
 Method to display a node, along with its children, and a proper XML document. More...
 
 attribute (attrname)
 Method to return a selected attribute's value. More...
 
 setAttribute (attrname, value="")
 Method to set a selected attribute's value. More...
 
 getElementsByTagName (thetag,...)
 Method to return all of the elements under this element with the specified tag name. More...
 
 getElementsById (theid)
 Method to return all of the elements under this element with the specified value of their id attribute. More...
 
 isChild (item)
 Method to check if the item is a child of this node. More...
 
 getParent (item)
 Method to get the parent of the item. More...
 
 removeChild (item)
 Method to remove item from the children of this node. More...
 

Static Public Member Functions

static _formattrlist (attrs)
 @provatesection Format a attribute list for inclusion in displayed XML. More...
 
static _quoteXML (text)
 Escape text for inclusion in displayed XML. More...
 
static validate (object)
 Validation typemethod. More...
 

Private Attributes

 _data
 The element's data. More...
 
 _children
 The element's children. More...
 

Detailed Description

A simple DOM element coded in Tcl using SNIT.

This class implements a simplified DOM element, that implements the getElementsByTagName and getElementsById methods, along with accessors to get data, attributes, and children of XML elements.

Parameters
nameElement name. Generally %%AUTO%% is passed.
_Options:
  • -tag The element's tag.
  • -attributes The element's attributes.
  • -opts The element's options.
Author
Robert Heller <heller@deepsoft.com>.

Constructor & Destructor Documentation

◆ SimpleDOMElement()

SimpleDOMElement::SimpleDOMElement ( name  ,
  ... 
)

The constructor.

Just sets the options.

Member Function Documentation

◆ _formattrlist()

static SimpleDOMElement::_formattrlist ( attrs  )
static

@provatesection Format a attribute list for inclusion in displayed XML.

Parameters
attrsThe attribute list as a alterning list of names and values.
Returns
A formatted and escaped attribute list string.

◆ _quoteXML()

static SimpleDOMElement::_quoteXML ( text  )
static

Escape text for inclusion in displayed XML.

Parameters
textUnescaped string.
Returns
A properly escaped XML string.

◆ addchild()

SimpleDOMElement::addchild ( childnode  )

Method to add a child node.

Parameters
childnodeThe child node to add.

◆ attribute()

SimpleDOMElement::attribute ( attrname  )

Method to return a selected attribute's value.

Parameters
attrnameThe name of the attribute.
Returns
The attribute's value or the empty string.

◆ children()

SimpleDOMElement::children ( )

Method to return the elements children.

Returns
The children.

◆ data()

SimpleDOMElement::data ( )

Method to return the element's data.

Returns
The data.

◆ display()

SimpleDOMElement::display ( fp  = "stdout",
indent  = "" 
)

Method to display a node, along with its children, and a proper XML document.

Parameters
fpChannel to write the display to.
indentThe indentation to use.

◆ getElementsById()

SimpleDOMElement::getElementsById ( theid  )

Method to return all of the elements under this element with the specified value of their id attribute.

Parameters
theidThe id value match.
Returns
A list of element object with the matching id value.

◆ getElementsByTagName()

SimpleDOMElement::getElementsByTagName ( thetag  ,
  ... 
)

Method to return all of the elements under this element with the specified tag name.

Parameters
thetagThe tag to match.
Returns
A list of element object with the matching tag.

◆ getParent()

SimpleDOMElement::getParent ( item  )

Method to get the parent of the item.

Parameters
itemThe item to get the parent of.
Returns
The parent node or {} if none found.

◆ isChild()

SimpleDOMElement::isChild ( item  )

Method to check if the item is a child of this node.

Parameters
itemThe possible child.
Returns
True if item is a child, false otherwise.

◆ length()

SimpleDOMElement::length ( )

Method to return the number of children.

Returns
The number of children.

◆ removeChild()

SimpleDOMElement::removeChild ( item  )

Method to remove item from the children of this node.

Parameters
itemThe item to remove.

◆ setAttribute()

SimpleDOMElement::setAttribute ( attrname  ,
value  = "" 
)

Method to set a selected attribute's value.

Parameters
attrnameThe name of the attribute.
valueThe value to set. Default is the empty string.

◆ setdata()

SimpleDOMElement::setdata ( )

Method to set the element's data.

Parameters
dThe new data.

◆ validate()

static SimpleDOMElement::validate ( object  )
static

Validation typemethod.

Raises an error if its argument is not a SimpleDOMElement object.

Parameters
objectThe object to typecheck.
Returns
The object or raise an error.

Member Data Documentation

◆ _children

SimpleDOMElement::_children
private

The element's children.

◆ _data

SimpleDOMElement::_data
private

The element's data.