eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'XML::Element':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Element (in XML)


Inheritance:

   Object
   |
   +--XML::Node
      |
      +--XML::Element

Package:
stx:goodies/xml/vw
Category:
XML-VW-Nodes
Version:
rev: 1.78 date: 2023/10/18 17:03:54
user: stefan
file: Element.st directory: goodies/xml/vw
module: stx stc-classLibrary: vw

Description:


XML document element boundaries are either delimited by start-tags and end-tags, or, for empty elements, by an empty-element tag. Each element has a type, identified by name, sometimes called its "generic identifier" (GI), and may have a set of attribute specifications. Each attribute specification has a name and a value.

Instance Variables:
	tag     <String | NodeTag>  the identifier for the element
	attributes      <Collection>  the element's attributes
	namespaces      <Dictionary>  a mapping of tag qualifiers to namespace URIs
	elements        <SequenceableCollection>  child text, comments, PIs and elements
	userData        <Object>  extra space for a client program to add annotations
	definition      <XML.Pattern>  defines the type constraints for the content


Class protocol:

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables

o  tag: tag
Modified (format): / 18-07-2018 / 11:53:15 / Claus Gittinger

o  tag: tag attributes: attributes

o  tag: tag attributes: attributes elements: elements
Modified (format): / 18-07-2018 / 11:53:10 / Claus Gittinger

o  tag: tag elements: elements
Modified (format): / 18-07-2018 / 11:53:02 / Claus Gittinger


Instance protocol:

accessing
o  anyElementNamed: elementName
Answer the one and only element named elementName.
Raise an error, if there is not exactly one element.
This will return the receiver if its name matches the requirement.

o  anyElementsNamed: elementName
Traverse the tree and return all the elements named elementName

o  attributes
Modified (format): / 21-04-2021 / 12:40:38 / cg

o  characterData
return all concatenated character data

o  characterDataDo: aBlock
recursively apply aBlock for every characterdata piece

o  characterDataOnto: str

o  childNodes
##add -umejava

o  definition

o  definition: aPattern

o  description

o  elementNamed: elementName

o  elementNamed: elementName ifAbsent: exceptionValue

o  elements
(comment from inherited method)
Visualworks uses the method #children to do essentially the same as this. Does not do much though

o  elementsNamed: elementName

o  elementsWithTextDo: aBlock
return all text elements

o  elementsWithTexts
return all text elements

o  elementsWithoutTexts
return a collection of all non-text elements

o  elementsWithoutTextsDo: aBlock
evaluate a block for all non-text elements

o  expandedName

o  hasElementNamed: elementName

o  hasElementsWithoutText
answer true, if there is a subelement, which is not text

o  indexOf: aChild

o  localName
for compatibility with YAXO nodes

o  namespaces: aDictionary

o  selectNodes: aBlock

o  tag

o  tagName

o  valueOfAttribute: attributeName ifAbsent: aBlock

accessing - xpath like
o  / anElementName
XPath like processing - answer all the elements named anElementName
(direct children; corresponds to ./anElementName in XPath)

Usage example(s):

Modified (comment): / 08-12-2020 / 12:45:58 / cg

o  // anElementName
XPath like processing - traverse the tree and answer all the elements named anElementName
(recursive; corresponds to .//anElementName in XPath)

o  /@ anAttributeName
XPath like processing - answer a nodeSet with attributes named anAttributeName

o  @ anAttributeName
XPath like processing - answer the attribute named anAttributeName

o  addAllAttributesNamed: attributeName to: aCollection
Recursively (depth-first) traverse the element tree and add any
sub-elements atributes named attributeName to aCollection

o  addAllElementsNamed: elementName to: aCollection
Recursively (depth-first) traverse the element tree and add any
sub-element named elementName to aCollection

o  addAttributesNamed: anAttributeName to: aCollection
XPath like processing - add attributes named anAttributeName to aCollection

o  addElementsNamed: elementName to: aCollection
Traverse the tree and add the direct child elements named elementName to aCollection

o  allAttributesNamed: attributeName do: aBlock
Recursively (depth-first) traverse the element tree and evaluate aBlock for each

o  allElementsNamed: elementName do: aBlock
Recursively (depth-first) traverse the element tree and evaluates aBlock for each

o  attributesNamed: anAttributeName do: aBlock
XPath like processing - evaluate aBlock for all attributes named anAttributeName

comparing
o  = anXmlElement
(comment from inherited method)
return true if the receiver and the arg have the same structure.
Notice:
This method is partially open coded (inlined) by the compiler(s)
identical objects are always considered equal.
redefining it may not work as expected.

o  hash
(comment from inherited method)
return an Integer useful as a hash key for the receiver.
This hash should return same values for objects with same
contents (i.e. use this to hash on structure)

copying
o  cloneTree
answer a copy of the tree, so that removal of child elements
from the copy does not affect the original node.

enumerating
o  childElementsDo: aBlock
enumerate my direct child-elements and
evaluate aBlock for each.

o  elementsDo: aBlock
recursively (depth-first) descend into my child-elements and
evaluate aBlock for each sub-element.
Bad naming: should be called allElementsDo:

o  nodesDo: aBlock
Evaluate aBlock for myself and recursively (depth-first) descend into my child-nodes and
evaluate aBlock for each sub-node.
Enumerates both attributes and elements

o  nodesReverseDo: aBlock

o  saxDo: aDriver forBodyDo: aBlock
a variation on #saxDo: that lets the client
control how the body of the element is to be
printed.

initialization
o  initialize

modifying
o  addNode: aNode
the following might look ugly, but saves a lot of memory,

o  removeAllNodes
##add -umejava

o  removeNode: aNode
remove a child node; raises an error if the given argument is
not a child of the receiver

namespaces
o  namespaceAt: qualifier

o  qualifierAtNamespace: ns

printing
o  prettyPrintColorizedOn: aStream depth: indent
(comment from inherited method)
depth should be named indent

o  prettyPrintOn: aStream depth: indent
(comment from inherited method)
self subclassResponsibility

o  printAsOneLineOn: aStream

o  printCanonicalOn: aStream
reject: [:str | str isBlankText]

o  printHTMLOn: aStream
reject: [:str | str isBlankText]

o  printNoIndentOn: aStream endSpacing: endSpacingBlock spacing: spacingBlock
(comment from inherited method)
Print myself on the stream with line breaks between adjacent
elements, but no indentation.

o  simpleDescription

private
o  attributes: attrColl

o  condenseList
condense the elements list;
if it is empty, make it nil;
otherwise, make it an array

o  condenseText
concatenate text elements into the smallest number of elements.
Return the receiver

o  elements: e

o  setAttributes: aCollection
private entries to set the attributes without reparenting

o  setElements: aCollection
private entries to set the elements without condensing

o  setTag: t attributes: a elements: e

private helpers
o  treePositionOf: aNode
return a collection containing the position of aNode in the document
in the form #(i1 i2 ... iN} where each iI is the index within the siblings

testing
o  hasSubNodes

o  isContent

o  isElement

o  isEmpty

o  isHTMLBlock

o  isLike: aNode

o  notEmpty

o  verifyContents

visiting
o  acceptVisitor: aVisitor
Double dispatch back to the visitor, passing my type encoded in
the selector (visitor pattern)



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:39:51 GMT