private static SetInfo parseSet(Node parent) throws XmlParserException { String id = ""; String type = ""; String measurementids = null; NodeList nodes = parent.getChildNodes(); Vector<SetInfo> sets = new Vector<SetInfo>(); for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) { Node node = nodes.item(nodeid); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element element = (Element) node; if (element.getTagName().equals("id")) id = element.getTextContent(); else if (element.getTagName().equals("set")) sets.add(parseSet(element)); else if (element.getTagName().equals("type")) type = element.getTextContent(); else if (element.getTagName().equals("measurementids")) measurementids = element.getTextContent(); } // create the set SetInfo set = new SetInfo(id, Integer.parseInt(type)); if (measurementids != null) { int mids[] = ByteArray.toIntArray(Base64.decode(measurementids), ByteArray.ENDIAN_LITTLE, 32); for (int mid : mids) set.addMeasurementID(mid); } // add the children for (SetInfo s : sets) set.addChild(s); return set; }
private static PeakData<? extends Peak> parsePeakData(Node parent) throws XmlParserException { // get the attributes Node typeattribute = parent.getAttributes().getNamedItem(PeakMLWriter.TYPE); if (typeattribute == null) throw new XmlParserException("Failed to locate a type attribute."); Node sizeattribute = parent.getAttributes().getNamedItem(PeakMLWriter.SIZE); if (sizeattribute == null) throw new XmlParserException("Failed to locate a size attribute."); int size = Integer.parseInt(sizeattribute.getNodeValue()); String type = typeattribute.getNodeValue(); // create the arrays int scanids[] = null; int patternids[] = null; int measurementids[] = null; double masses[] = null; double intensities[] = null; double retentiontimes[] = null; // retrieve all the data NodeList nodes = parent.getChildNodes(); for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) { Node node = nodes.item(nodeid); if (node.getNodeType() != Node.ELEMENT_NODE) continue; Element element = (Element) node; if (element.getTagName().equals("scanids")) scanids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("patternids")) patternids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("measurementids")) measurementids = ByteArray.toIntArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("masses")) masses = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("intensities")) intensities = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); else if (element.getTagName().equals("retentiontimes")) retentiontimes = ByteArray.toDoubleArray( Base64.decode(element.getTextContent()), ByteArray.ENDIAN_LITTLE, 32); } // create the PeakData instance if (type.equals("centroid")) return new PeakData<Centroid>( Centroid.factory, size, scanids, patternids, measurementids, masses, intensities, retentiontimes); return null; }