Class XMLTree1

All Implemented Interfaces:
XMLTree

public class XMLTree1 extends XMLTreeSecondary
XMLTree represented as a recursive data structure, done "bare-handed", with implementations of all methods.
  • Constructor Summary

    Constructors
    Constructor
    Description
    XMLTree1(String source)
    Constructs an XMLTree from input source (could be a file or a URL).
    XMLTree1(String source, boolean trimWhitespace)
    Constructs an XMLTree from input source (could be a file or a URL).
  • Method Summary

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

    Methods inherited from class components.xmltree.XMLTreeSecondary

    equals, hashCode, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • XMLTree1

      public XMLTree1(String source)
      Constructs an XMLTree from input source (could be a file or a URL). Leading and trailing whitespace is trimmed from text nodes.
      Parameters:
      source - XML input
      Requires:
      source is the name of a file or a URL
      Ensures:
      this = [the XMLTree corresponding to the given input source,
              with whitespace trimmed]
    • XMLTree1

      public XMLTree1(String source, boolean trimWhitespace)
      Constructs an XMLTree from input source (could be a file or a URL).
      Parameters:
      source - XML input
      trimWhitespace - flag to indicate whether leading and trailing whitespace should be trimmed from text nodes
      Requires:
      source is the name of a file or a URL
      Ensures:
      this = [the XMLTree corresponding to the given input source,
              with whitespace trimmed only if trimWhitespace]
  • Method Details

    • label

      public final String label()
      Description copied from interface: XMLTree
      Returns the label of the root of this.
      Returns:
      the label of the root of this
    • isTag

      public final boolean isTag()
      Description copied from interface: XMLTree
      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
    • hasAttribute

      public final boolean hasAttribute(String name)
      Description copied from interface: XMLTree
      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
    • attributeValue

      public final String attributeValue(String name)
      Description copied from interface: XMLTree
      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
    • numberOfChildren

      public final int numberOfChildren()
      Description copied from interface: XMLTree
      Returns the number of subtrees of the root of this.
      Returns:
      the number of subtrees of the root of this
    • child

      public final XMLTree child(int k)
      Description copied from interface: XMLTree
      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
    • attributeNames

      public final Iterable<String> attributeNames()
      Description copied from interface: XMLTree
      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
    • display

      public final void display()
      Description copied from interface: XMLTree
      Displays this in a new window with a default title.
    • display

      public final void display(String title)
      Description copied from interface: XMLTree
      Displays this in a new window with the given title.
      Parameters:
      title - the window title