コード例 #1
0
  /**
   * This method is called when the start of an XML element is encountered. Instantiates new objects
   * when necessary and lets the characters method know what kind of action to take.
   *
   * @param name Name of the element that is encountered.
   * @param atts The attributes encountered.
   * @throws SAXException Exception thrown if is wrong type of XML file.
   */
  public void startElement(String namespace, String name, String qName, Attributes atts)
      throws SAXException {
    // Make sure is correct file type
    if (count == 0)
      if (!name.equals("feature_vector_file") && !qName.equals("feature_vector_file"))
        throw new SAXException("\n\nIt is in reality of the type " + name + ".");
    count++;

    // Identify the type of tag
    tag_identifier = 0;
    if (name.equals("data_set") || qName.equals("data_set")) {
      // Create a new Dataset and add it to root_datasets.
      current_root_dataset = new DataSet();
      root_datasets.add(current_root_dataset);
    } else if (name.equals("section") || qName.equals("section")) {
      // Create a new set of sub-sets of a data set if subset_datasets is null
      if (subset_datasets == null) subset_datasets = new LinkedList<DataSet>();

      // Create a new sub-set DataSet. Place this DataSet in the list of
      // sub-set DataSets and gives it a reference to it's parent root
      // DataSet.
      current_subset_dataset = new DataSet();
      current_subset_dataset.parent = current_root_dataset;
      subset_datasets.add(current_subset_dataset);

      // Extract the name of the DataSet from the id attribute
      current_subset_dataset.start = Double.parseDouble(atts.getValue(0));
      current_subset_dataset.stop = Double.parseDouble(atts.getValue(1));
    } else if (name.equals("feature") || qName.equals("feature")) {
      // Prepare the linked lists to store feature values
      if (feature_name_list == null) {
        feature_name_list = new LinkedList<String>();
        feature_values_list = new LinkedList<double[]>();
      }
      feature_indidual_values_list = new LinkedList<String>();
    } else if (name.equals("data_set_id") || qName.equals("data_set_id")) tag_identifier = 1;
    else if (name.equals("name") || qName.equals("name")) tag_identifier = 2;
    else if (name.equals("v") || qName.equals("v")) tag_identifier = 3;
  }