class Element
class Element
lib/xml/element.tya:2
Element provides the xml/Element standard library API.
Source
# Element provides the xml/Element standard library API.
class Element
# Element.attrs stores instance state.
# @type Nil
attrs: nil
# Element.children stores instance state.
# @type Nil
children: nil
# Element.name stores instance state.
# @type Nil
name: nil
# Element.initialize provides the xml/Element standard library operation.
# @param name String name value.
# @param attrs Any attrs value.
# @param children Any children value.
# @return Self the initialized object.
initialize: name, attrs, children ->
self.name = name
self.attrs = attrs
self.children = children
# Element.attr provides the xml/Element standard library operation.
# @param name String name value.
# @param default Any default value.
# @return Any the resulting value.
attr: name, default ->
self.attrs.get(name, default)
# Element.child_elements provides the xml/Element standard library operation.
# @return Any the resulting value.
child_elements: ->
out = []
i = 0
while i < self.children.len()
if self.children[i].class == Element
out.push(self.children[i])
i = i + 1
out
# Element.find provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find: name ->
found = self.find_all(name)
if found.len() == 0
return nil
found[0]
# Element.find_all provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_all: name ->
out = []
children = self.child_elements()
i = 0
while i < children.len()
if children[i].name == name
out.push(children[i])
i = i + 1
out
# Element.find_all_recursive provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_all_recursive: name ->
out = []
Xml(nil).collect_recursive(self, name, out)
out
# Element.find_recursive provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_recursive: name ->
found = self.find_all_recursive(name)
if found.len() == 0
return nil
found[0]
# Element.has_attr? provides the xml/Element standard library operation.
# @param name String name value.
# @return Boolean whether the condition is true.
has_attr?: name ->
self.attrs.has?(name)
# Element.new provides the xml/Element standard library operation.
# @param name String name value.
# @param attrs Any attrs value.
# @param children Any children value.
# @return Self the resulting value.
new: name, attrs, children ->
Element(name, attrs, children)
# Element.text provides the xml/Element standard library operation.
# @return String the resulting value.
text: ->
out = ""
i = 0
while i < self.children.len()
child = self.children[i]
if child.class == Text or child.class == CData
out = out + child.text
elseif child.class == Element
out = out + child.text()
i = i + 1
out
# Element.to_s provides the xml/Element standard library operation.
# @return String the resulting value.
to_s: ->
Xml(nil).stringify(self)
Instance Variables
attrs
Element.attrs
lib/xml/element.tya:5
Element.attrs stores instance state.
Source
# Element.attrs stores instance state.
# @type Nil
attrs: nil
children
Element.children
lib/xml/element.tya:9
Element.children stores instance state.
Source
# Element.children stores instance state.
# @type Nil
children: nil
name
Element.name
lib/xml/element.tya:13
Element.name stores instance state.
Source
# Element.name stores instance state.
# @type Nil
name: nil
Methods
attr
Element.attr(name, default)
lib/xml/element.tya:29
Element.attr provides the xml/Element standard library operation.
Source
# Element.attr provides the xml/Element standard library operation.
# @param name String name value.
# @param default Any default value.
# @return Any the resulting value.
attr: name, default ->
self.attrs.get(name, default)
child_elements
Element.child_elements()
lib/xml/element.tya:34
Element.child_elements provides the xml/Element standard library operation.
Source
# Element.child_elements provides the xml/Element standard library operation.
# @return Any the resulting value.
child_elements: ->
out = []
i = 0
while i < self.children.len()
if self.children[i].class == Element
out.push(self.children[i])
i = i + 1
out
find
Element.find(name)
lib/xml/element.tya:46
Element.find provides the xml/Element standard library operation.
Source
# Element.find provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find: name ->
found = self.find_all(name)
if found.len() == 0
return nil
found[0]
find_all
Element.find_all(name)
lib/xml/element.tya:55
Element.find_all provides the xml/Element standard library operation.
Source
# Element.find_all provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_all: name ->
out = []
children = self.child_elements()
i = 0
while i < children.len()
if children[i].name == name
out.push(children[i])
i = i + 1
out
find_all_recursive
Element.find_all_recursive(name)
lib/xml/element.tya:68
Element.find_all_recursive provides the xml/Element standard library operation.
Source
# Element.find_all_recursive provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_all_recursive: name ->
out = []
Xml(nil).collect_recursive(self, name, out)
out
find_recursive
Element.find_recursive(name)
lib/xml/element.tya:76
Element.find_recursive provides the xml/Element standard library operation.
Source
# Element.find_recursive provides the xml/Element standard library operation.
# @param name String name value.
# @return Any the resulting value.
find_recursive: name ->
found = self.find_all_recursive(name)
if found.len() == 0
return nil
found[0]
has_attr?
Element.has_attr?(name)
lib/xml/element.tya:85
Element.has_attr? provides the xml/Element standard library operation.
Source
# Element.has_attr? provides the xml/Element standard library operation.
# @param name String name value.
# @return Boolean whether the condition is true.
has_attr?: name ->
self.attrs.has?(name)
initialize
Element.initialize(name, attrs, children)
lib/xml/element.tya:20
Element.initialize provides the xml/Element standard library operation.
Source
# Element.initialize provides the xml/Element standard library operation.
# @param name String name value.
# @param attrs Any attrs value.
# @param children Any children value.
# @return Self the initialized object.
initialize: name, attrs, children ->
self.name = name
self.attrs = attrs
self.children = children
new
Element.new(name, attrs, children)
lib/xml/element.tya:93
Element.new provides the xml/Element standard library operation.
Source
# Element.new provides the xml/Element standard library operation.
# @param name String name value.
# @param attrs Any attrs value.
# @param children Any children value.
# @return Self the resulting value.
new: name, attrs, children ->
Element(name, attrs, children)
text
Element.text()
lib/xml/element.tya:98
Element.text provides the xml/Element standard library operation.
Source
# Element.text provides the xml/Element standard library operation.
# @return String the resulting value.
text: ->
out = ""
i = 0
while i < self.children.len()
child = self.children[i]
if child.class == Text or child.class == CData
out = out + child.text
elseif child.class == Element
out = out + child.text()
i = i + 1
out
to_s
Element.to_s()
lib/xml/element.tya:112
Element.to_s provides the xml/Element standard library operation.
Source
# Element.to_s provides the xml/Element standard library operation.
# @return String the resulting value.
to_s: ->
Xml(nil).stringify(self)