Hello again denis:
Look if this looks like you wanna get.
Regards.
package testbetwixt;
public class Parser {
/**
* @param args
*/
public static void main(String[] args) {
ListContainer itemToParse = new ListContainer();
itemToParse.addElement("foo");
itemToParse.addElement("bar");
itemToParse.addElement("09089787767");
itemToParse.addElement("767576565");
itemToParse.setOtherElement("yetanotherElement");
try {
System.out.println("Item to XML");
System.out.println(itemToParse.toXML());
System.out.println("XML to Item");
ListContainer anotherListContainer =
ListContainer.parseXML(itemToParse.toXML());
System.out.println("The parsed item to XML");
System.out.println(anotherListContainer.toXML());
} catch(Exception e) {
e.printStackTrace();
}
}
}
<?xml version='1.0' encoding='UTF-8' ?>
<info>
<element name='myxml'>
<element name='somecontainerelement'>
<element name='element' property='elementIterator' adder='addElement' class='java.lang.String' />
</element>
<element name='otherElement' property='otherElement' />
<addDefaults/>
</element>
</info>
package testbetwixt;
import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.LinkedList;
import java.util.ListIterator;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanWriter;
import org.xml.sax.SAXException;
public class ListContainer {
private LinkedList theList;
private String otherElement = "";
public ListContainer() { this.theList = new LinkedList(); }
public ListIterator getElementIterator() { return
this.theList.listIterator(); }
public void addElement(String element) { this.theList.add(element); }
public String getOtherElement() { return this.otherElement; }
public void setOtherElement(String otherElement) { this.otherElement =
otherElement; }
public String toXML() throws IOException, IntrospectionException,
SAXException {
StringWriter outputWriter = new StringWriter();
outputWriter.write("<?xml version='1.0'
encoding=\"ISO-8859-1\"?>\n");
BeanWriter beanWriter = new BeanWriter(outputWriter);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.enablePrettyPrint();
beanWriter.write("somecontainerelement", this);
String ret = outputWriter.toString();
outputWriter.close();
return ret;
}
public static ListContainer parseXML(String xml) throws IOException,
SAXException, IntrospectionException {
StringReader xmlReader = new StringReader(xml);
BeanReader beanReader = new BeanReader();
beanReader.getBindingConfiguration().setMapIDs(false);
beanReader.registerBeanClass("somecontainerelement",
ListContainer.class);
return (ListContainer)beanReader.parse(xmlReader);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]