M
Myriam Abramson
Hello,
I want to write out an XML encoded java bean with an array. I
understand that is an indexed property of the bean. Here's what I've
done below. That does not work and I do not get the values of the
array in the XML encoded output. Any ideas? thks.
import java.io.*;
import java.util.*;
import java.beans.XMLEncoder;
public class MyBean implements Serializable {
public String [] myvalues = {"Sarah", "Simbah"};
public MyBean () {
}
public String getmyvalues(int index) {
return myvalues[index];
}
public void setmyvalues (int index, String name) {
myvalues[index] = name;
}
public String [] getmyvalues () {
return myvalues;
}
public void setmyvalues (String [] elements) {
myvalues = elements;
}
public void save () throws Exception {
XMLEncoder e = new XMLEncoder
(new BufferedOutputStream(new FileOutputStream ("mybean" + ".xml")));
e.writeObject(this);
e.flush();
e.close();
}
public static void main (String [] str) throws Exception {
MyBean mb = new MyBean();
mb.save();
}
}
I want to write out an XML encoded java bean with an array. I
understand that is an indexed property of the bean. Here's what I've
done below. That does not work and I do not get the values of the
array in the XML encoded output. Any ideas? thks.
import java.io.*;
import java.util.*;
import java.beans.XMLEncoder;
public class MyBean implements Serializable {
public String [] myvalues = {"Sarah", "Simbah"};
public MyBean () {
}
public String getmyvalues(int index) {
return myvalues[index];
}
public void setmyvalues (int index, String name) {
myvalues[index] = name;
}
public String [] getmyvalues () {
return myvalues;
}
public void setmyvalues (String [] elements) {
myvalues = elements;
}
public void save () throws Exception {
XMLEncoder e = new XMLEncoder
(new BufferedOutputStream(new FileOutputStream ("mybean" + ".xml")));
e.writeObject(this);
e.flush();
e.close();
}
public static void main (String [] str) throws Exception {
MyBean mb = new MyBean();
mb.save();
}
}