All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.xmlOnline.tree.Element

java.lang.Object
   |
   +----w3c.xmlOnline.tree.Node
           |
           +----w3c.xmlOnline.tree.Element

public class Element
extends Node
Class that holds an element node in the XML tree. It has a dictionary of attributes and values, and a list of children. The children and attributes can be other elements, processing instructions, comments or text nodes. By convention, all element names and attribute names are stored in lowercase (but nothing in this class checks or enforces that).

Version:
$Id: w3c.xmlOnline.tree.Element.html,v 1.7 1997/06/09 22:25:51 bbos Exp $
Author:
Bert Bos

Variable Index

 o attrs
 o children
 o name

Constructor Index

 o Element(Node, String, int)
Create a new XML Element node with the given name.

Method Index

 o addAttribute(String, String)
Add (or change) an attribute/value pair to this element.
 o addChild(Node)
Add a child node at the end of the list of children of this element.
 o addID(String, Element)
Add the caller to the idTable of the root of this tree, with the given ID as key.
 o attributes()
Return an Enumeration of the attribute names of this element.
 o attributeValue(String)
Return the value of the attribute with name `name', or null if the attribute doesn't exist.
 o children()
Return an Enumeration of the child nodes of this element.
 o data()
Return the concatenation of all Data nodes inside the element.
 o dumpTree(PrintStream)
A method to write out the content of the node in correct XML synyax.
 o findID(String)
Return the element with a certain ID in the tree around this element.
 o getChild(int)
Get n'th child (n >= 1).
 o getNodeByNumber(int)
Get the node with seqno n from the subtree below this node.
 o ids()
Return an enumeration of all IDs in the tree.
 o lastSeqno()
Return the highest seqno in the subtree of this node.
 o name()
Return the name of this element, or null.
 o nrChildren()
Return the number of children.
 o nrNodes()
Return the number of nodes in the subtree below this node
 o renumber(int[])
Renumber the nodes.
 o replaceBy(Node, Node)
Replace a child node by a different node.
 o replaceBy(Node, Node[])
Replace a child node by a list of different nodes.
 o setName(String)
Set the name of the element

Variables

 o name
 protected String name
 o attrs
 protected Hashtable attrs
 o children
 protected Vector children

Constructors

 o Element
 public Element(Node parent,
                String name,
                int nr)
Create a new XML Element node with the given name.

Parameters:
parent - the parent of the node
name - the name of the new element node
nr - the sequence number of the node in the tree
Returns:
the new Element node

Methods

 o setName
 public Element setName(String name)
Set the name of the element

Parameters:
root - the name of the start element
Returns:
the new Root node
 o name
 public String name()
Return the name of this element, or null.

Returns:
the name of this element, or null
 o addChild
 public Element addChild(Node c)
Add a child node at the end of the list of children of this element.

Parameters:
c - the node to add
Returns:
this
 o children
 public Enumeration children()
Return an Enumeration of the child nodes of this element.

Returns:
an Enumeration of the child nodes of this element
See Also:
Enumeration
 o nrChildren
 public int nrChildren()
Return the number of children.

Returns:
the number of children
 o replaceBy
 protected Node replaceBy(Node child,
                          Node nodes[])
Replace a child node by a list of different nodes.

Parameters:
child - the child node to replace
nodes - the nodes that are to replace the child
Overrides:
replaceBy in class Node
 o replaceBy
 protected Node replaceBy(Node child,
                          Node node)
Replace a child node by a different node.

Parameters:
child - the child node to replace
node - the node that is to replace the child
Overrides:
replaceBy in class Node
 o addAttribute
 public Element addAttribute(String name,
                             String value)
Add (or change) an attribute/value pair to this element. If the attribute name is "ID", the element is added to the table of elements indexed on ID, that is kept by the root.

Parameters:
name - the name of the attribute
value - the value of the attribute
Returns:
this
 o attributes
 public Enumeration attributes()
Return an Enumeration of the attribute names of this element.

Returns:
an Enumeration of the attribute names
 o attributeValue
 public String attributeValue(String name)
Return the value of the attribute with name `name', or null if the attribute doesn't exist.

Parameters:
name - the name of an attribute (lowercase)
Returns:
the value of the attribute, or null
 o getChild
 public Node getChild(int n)
Get n'th child (n >= 1). If n is too large, it returns null.

Parameters:
n - the number of the child to return
Returns:
the child, or null
 o getNodeByNumber
 public Node getNodeByNumber(int n)
Get the node with seqno n from the subtree below this node.

Parameters:
n - the seqno to look for
Returns:
the node with seqno n in the subtree, or null
Overrides:
getNodeByNumber in class Node
 o nrNodes
 public int nrNodes()
Return the number of nodes in the subtree below this node

Returns:
the number of nodes in the subtree below this node
Overrides:
nrNodes in class Node
 o lastSeqno
 public int lastSeqno()
Return the highest seqno in the subtree of this node.

Overrides:
lastSeqno in class Node
 o renumber
 protected void renumber(int n_in_out[])
Renumber the nodes.

Parameters:
n - the starting number
Overrides:
renumber in class Node
 o addID
 protected Node addID(String ID,
                      Element elt)
Add the caller to the idTable of the root of this tree, with the given ID as key. An element that has an attribute called "ID" will use this method to add itself to the idTable of its root element. This call percolates up the tree until it reaches a Root element.

Parameters:
ID - the ID to use as key (value of ID attribute)
elt - the element to add
Returns:
this
Overrides:
addID in class Node
 o findID
 public Node findID(String ID)
Return the element with a certain ID in the tree around this element. The request is passed up the tree to the Root, which will look up the ID in its hash table.

Parameters:
ID - the ID to look for
Returns:
the element with that ID, or null
Overrides:
findID in class Node
 o ids
 public Enumeration ids()
Return an enumeration of all IDs in the tree. If this Root is not the root of the tree, it will pass the request up to the real root.

Returns:
an enumeration of all IDs in the tree
Overrides:
ids in class Node
 o data
 public String data()
Return the concatenation of all Data nodes inside the element.

 o dumpTree
 public void dumpTree(PrintStream out)
A method to write out the content of the node in correct XML synyax.

Parameters:
out - the PrintStream to write on
Overrides:
dumpTree in class Node

All Packages  Class Hierarchy  This Package  Previous  Next  Index