private void toXml(XmppStreamWriter out, DataOption option) throws IOException, XMLStreamException { out.writeStartElement("option"); if (option.getLabel() != null) out.writeAttribute("label", option.getLabel()); DataValue[] values = option.getValue(); if (values != null) { for (int i = 0; i < values.length; i++) { DataValue value = values[i]; out.writeStartElement("value"); out.writeCharacters(value.getValue()); out.writeEndElement(); // </value> } } out.writeEndElement(); // </option> }
/** Deserializes the object from XML */ public DataOption parseOption(XMLStreamReader in) throws IOException, XMLStreamException { String label = in.getAttributeValue(null, "label"); DataOption option = new DataOption(label); ArrayList<DataValue> valueList = new ArrayList<DataValue>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { option.setValueList(valueList); return option; } if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) { String value = in.getElementText(); valueList.add(new DataValue(value)); skipToEnd(in, "value"); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "option"); return option; }