Package components.xmltree
Interface XMLTree
- All Known Implementing Classes:
XMLTree1
,XMLTree2
,XMLTreeSecondary
public interface XMLTree
XMLTree component with all its methods. (Note: by package-wide convention,
all references are non-null.)
An XMLTree is modeled by a tree where each node has a label (either a tag or some text) and if the label is a tag, the node also has a set of (attribute, value) pairs.
There are two constructors. One takes the name of a file or a URL and a boolean flag, and constructs an XMLTree corresponding to the XML read from the file or URL. The boolean flag indicates whether leading/trailing whitespace should be trimmed from text nodes. The second constructor only takes the name of a file or a URL and behaves exactly as if the first constructor was invoked with a true flag (i.e., by default it trims whitespace).
An XMLTree is modeled by a tree where each node has a label (either a tag or some text) and if the label is a tag, the node also has a set of (attribute, value) pairs.
There are two constructors. One takes the name of a file or a URL and a boolean flag, and constructs an XMLTree corresponding to the XML read from the file or URL. The boolean flag indicates whether leading/trailing whitespace should be trimmed from text nodes. The second constructor only takes the name of a file or a URL and behaves exactly as if the first constructor was invoked with a true flag (i.e., by default it trims whitespace).
-
Method Summary
Modifier and TypeMethodDescriptionReturns anIterable<String>
of the attribute names of the root ofthis
.attributeValue
(String name) Returns the value associated with the attribute of the root tag ofthis
calledname
.child
(int k) Returns thek
-th subtree of the root ofthis
.void
display()
Displaysthis
in a new window with a default title.void
Displaysthis
in a new window with the giventitle
.boolean
hasAttribute
(String name) Returns whether the root tag ofthis
has an attribute calledname
.boolean
isTag()
Returns whether the label of the root ofthis
is a tag.label()
Returns the label of the root ofthis
.int
Returns the number of subtrees of the root ofthis
.toString()
Returns the XML string representation ofthis
.
-
Method Details
-
label
Returns the label of the root ofthis
.- Returns:
- the label of the root of
this
- Ensures:
label = [the label of the root of this (not including <> for tags)]
-
isTag
boolean isTag()Returns whether the label of the root ofthis
is a tag.- Returns:
- true iff the label of the root of
this
is a tag - Ensures:
isTag = [the label of the root of this is a tag]
-
hasAttribute
Returns whether the root tag ofthis
has an attribute calledname
.- Parameters:
name
- the name of the possible attribute- Returns:
- true iff the root tag of
this
has an attribute calledname
- Requires:
[the label of the root of this is a tag]
- Ensures:
hasAttribute = [label of the root of this has an attribute called name]
-
attributeValue
Returns the value associated with the attribute of the root tag ofthis
calledname
.- Parameters:
name
- the name of the attribute- Returns:
- the value associated to attribute
name
of the root tag ofthis
- Requires:
[the label of the root of this is a tag and it has an attribute called name]
- Ensures:
attributeValue = [the value associated with attribute name of the root tag of this]
-
numberOfChildren
int numberOfChildren()Returns the number of subtrees of the root ofthis
.- Returns:
- the number of subtrees of the root of
this
- Requires:
[the label of the root of this is a tag]
- Ensures:
numberOfChildren = [the number of subtrees of the root of this]
-
child
Returns thek
-th subtree of the root ofthis
.- Parameters:
k
- the subtree to return- Returns:
- the
k
-th subtree of the root ofthis
- Requires:
[the label of the root of this is a tag and 0 <= k < the number of subtrees of the root of this]
- Ensures:
child = [the k-th subtree of the root of this]
-
attributeNames
Returns anIterable<String>
of the attribute names of the root ofthis
.- Returns:
- an
Iterable<String>
of the attribute names of the root ofthis
- Requires:
[the label of the root of this is a tag]
- Ensures:
attributeNames = [an Iterable<String> of the attribute names of the root of this]
-
display
void display()Displaysthis
in a new window with a default title.- Ensures:
[this is displayed in a new window]
-
display
Displaysthis
in a new window with the giventitle
.- Parameters:
title
- the window title- Ensures:
[this is displayed in a new window]
-
toString
Returns the XML string representation ofthis
.
-