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).
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an Iterable<String> of the attribute names of the root of this.
    Returns the value associated with the attribute of the root tag of this called name.
    child(int k)
    Returns the k-th subtree of the root of this.
    void
    Displays this in a new window with a default title.
    void
    display(String title)
    Displays this in a new window with the given title.
    boolean
    Returns whether the root tag of this has an attribute called name.
    boolean
    Returns whether the label of the root of this is a tag.
    Returns the label of the root of this.
    int
    Returns the number of subtrees of the root of this.
    Returns the XML string representation of this.
  • Method Details

    • label

      Returns the label of the root of this.
      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 of this 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

      boolean hasAttribute(String name)
      Returns whether the root tag of this has an attribute called name.
      Parameters:
      name - the name of the possible attribute
      Returns:
      true iff the root tag of this has an attribute called name
      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 of this called name.
      Parameters:
      name - the name of the attribute
      Returns:
      the value associated to attribute name of the root tag of this
      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

      Returns the number of subtrees of the root of this.
      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

      XMLTree child(int k)
      Returns the k-th subtree of the root of this.
      Parameters:
      k - the subtree to return
      Returns:
      the k-th subtree of the root of this
      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 an Iterable<String> of the attribute names of the root of this.
      Returns:
      an Iterable<String> of the attribute names of the root of this
      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()
      Displays this in a new window with a default title.
      Ensures:
      [this is displayed in a new window]
    • display

      void display(String title)
      Displays this in a new window with the given title.
      Parameters:
      title - the window title
      Ensures:
      [this is displayed in a new window]
    • toString

      Returns the XML string representation of this.
      Overrides:
      toString in class Object
      Returns:
      the XML string representation of this
      Ensures:
      toString = [the XML string representation of this]