i use xstream (http://x-stream.github.io/) write java objects xml , read xml files in java objects, so;
// writing java object xml file xmlfile = new file("/", "myobject.xml"); fileoutputstream out = new fileoutputstream(xmlfile); myobject myobject = new myobject(); xstream.toxml(myobject, out); // reading java object in again fileinputstream xmlfile = ... xstream xstream = new xstream(); myobject myobject = xstream.fromxml(xmlfile); basically, want include info in xml file when write - e.g. 'version1', either xml comments or other way of embedding info - possible?
so when read xml file in again, i'd able retrieve info.
note, know add string field or whatever myobject - can't in case (i.e. modify myobject).
many thanks!
as makky points out, xstream ignores comment, got work doing following;
// writing comment @ top of xml file, writing java object xml file file xmlfile = new file("/", "myobject.xml"); fileoutputstream out = new fileoutputstream(xmlfile); string xmlcomment = "<!-- comment -->" out.write(xmlcomment.getbytes()); out.write("\n".getbytes()); myobject myobject = new myobject(); xstream.toxml(myobject, out); // reading comment xml file, deserilizing object; final filebasedlinereader xmlfilebasedlinereader = new filebasedlinereader(xmlfile); final string commentinxmlfile = xmlfilebasedlinereader.nextline(); fileinputstream xmlfile = ... xstream xstream = new xstream(); myobject myobject = xstream.fromxml(xmlfile);
Comments
Post a Comment