Guest User

Untitled

a guest
Jan 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <Objects>
  2. <Object Type="System.Tuning" >4456</Object>
  3. <Object Type="System.Lag" >7789</Object>
  4. </Objects>
  5.  
  6. class ParentResponseObject {
  7. List <ResponseObject>responseObjects = new ArrayList<ResponseObject>();
  8. public ParentResponseObject() {
  9. // TODO Auto-generated constructor stub
  10. }
  11. }
  12. class ResponseObject {
  13. String Type;
  14. String Value;
  15. public ResponseObject() {
  16.  
  17. }
  18. }
  19.  
  20. XStream s = new XStream(new DomDriver());
  21. s.alias("Objects", src.core.PowerShell.MyAgain.ParentResponseObject.class);
  22. s.alias("Object", src.core.PowerShell.MyAgain.ResponseObject.class);
  23. s.useAttributeFor(src.core.PowerShell.MyAgain.ResponseObject.class, "Type");
  24. s.addImplicitCollection(src.core.PowerShell.MyAgain.ParentResponseObject.class, "responseObjects");
  25. ParentResponseObject gh =(ParentResponseObject)s.fromXML(k1);
  26.  
  27. @XStreamAlias("Object")
  28. @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "value" })
  29. public class ResponseObject {
  30.  
  31. @XStreamAlias("Type")
  32. private String type;
  33.  
  34. private String value;
  35.  
  36. public ResponseObject() {
  37. }
  38.  
  39. public String getType() {
  40. return type;
  41. }
  42.  
  43. public String getValue() {
  44. return value;
  45. }
  46. }
  47.  
  48. @XStreamAlias("Objects")
  49. public class ParentResponseObject {
  50.  
  51. @XStreamImplicit
  52. private final List <ResponseObject> responseObjects = new ArrayList<ResponseObject>();
  53.  
  54. public ParentResponseObject() {
  55. }
  56.  
  57. public List<ResponseObject> getResponseObjects() {
  58. return responseObjects;
  59. }
  60. }
  61.  
  62. XStream xStream = new XStream();
  63. xStream.processAnnotations(ParentResponseObject.class);
  64. ParentResponseObject parent = (ParentResponseObject)xStream.fromXML(file);
  65. for (ResponseObject o : parent.getResponseObjects()) {
  66. System.out.println(o.getType() + ":" + o.getValue());
  67. }
Add Comment
Please, Sign In to add comment