Created
June 12, 2013 14:14
-
-
Save Alcar32/5765651 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package example; | |
| import java.beans.XMLEncoder; | |
| import java.io.ByteArrayOutputStream; | |
| import java.util.Vector; | |
| public class XmlEncodeToString { | |
| public static void main(String[] args) throws Exception { | |
| MyBean mb = new MyBean(); | |
| mb.setMyBoolean(true); | |
| mb.setMyString("xml is cool"); | |
| Vector<String> v = new Vector<String>(); | |
| v.add("one"); | |
| v.add("two"); | |
| v.add("three"); | |
| mb.setMyVector(v); | |
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
| XMLEncoder xmlEncoder = new XMLEncoder(baos); | |
| xmlEncoder.writeObject(mb); | |
| xmlEncoder.close(); | |
| String xml = baos.toString(); | |
| System.out.println(xml); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment