private int extractPrecursorCharge(Spectrum spectrum) {
    PrecursorList precursorListElement = spectrum.getPrecursorList();
    if ((precursorListElement == null) || (precursorListElement.getCount().equals(0))) return 0;

    List<Precursor> precursorList = precursorListElement.getPrecursor();
    for (Precursor parent : precursorList) {

      SelectedIonList selectedIonListElement = parent.getSelectedIonList();
      if ((selectedIonListElement == null) || (selectedIonListElement.getCount().equals(0)))
        return 0;
      List<ParamGroup> selectedIonParams = selectedIonListElement.getSelectedIon();
      if (selectedIonParams == null) continue;

      for (ParamGroup pg : selectedIonParams) {
        List<CVParam> pgCvParams = pg.getCvParam();
        for (CVParam param : pgCvParams) {
          String accession = param.getAccession();
          String value = param.getValue();
          if ((accession == null) || (value == null)) continue;
          if (accession.equals("MS:1000041")) {
            int precursorCharge = Integer.parseInt(value);
            return precursorCharge;
          }
        }
      }
    }
    return 0;
  }
  private double extractPrecursorMz(Spectrum spectrum) {

    PrecursorList precursorListElement = spectrum.getPrecursorList();
    if ((precursorListElement == null) || (precursorListElement.getCount().equals(0))) return 0;

    List<Precursor> precursorList = precursorListElement.getPrecursor();
    for (Precursor parent : precursorList) {

      SelectedIonList selectedIonListElement = parent.getSelectedIonList();
      if ((selectedIonListElement == null) || (selectedIonListElement.getCount().equals(0)))
        return 0;
      List<ParamGroup> selectedIonParams = selectedIonListElement.getSelectedIon();
      if (selectedIonParams == null) continue;

      for (ParamGroup pg : selectedIonParams) {
        List<CVParam> pgCvParams = pg.getCvParam();
        for (CVParam param : pgCvParams) {
          String accession = param.getAccession();
          String value = param.getValue();
          if ((accession == null) || (value == null)) continue;
          // MS:1000040 is used in mzML 1.0,
          // MS:1000744 is used in mzML 1.1.0
          if (accession.equals("MS:1000040") || accession.equals("MS:1000744")) {
            double precursorMz = Double.parseDouble(value);
            return precursorMz;
          }
        }
      }
    }
    return 0;
  }