Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Objects>
- <Object Type="System.Management.Automation.Internal.Host.InternalHost">
- <Property Name="Name" Type="System.String">ConsoleHost</Property>
- <Property Name="Version" Type="System.Version">2.0</Property>
- <Property Name="InstanceId" Type="System.Guid">7e2156</Property>
- </Object>
- </Objects>
- class ParentResponseObject {
- List <ResponseObject>responseObjects = new ArrayList<ResponseObject>();
- }
- @XStreamAlias("Object")
- @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
- class ResponseObject {
- String Type;
- String Value;
- List <Properties> properties = new ArrayList<Properties>();
- }
- @XStreamAlias("Property")
- @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
- class Properties {
- String Name;
- String Type;
- String Value;
- }
- public class MyAgainTest {
- public static void main (String[] args) throws Exception {
- String k1 = //collect the xml as string
- XStream s = new XStream(new DomDriver());
- s.alias("Objects", ParentResponseObject.class);
- s.alias("Object", ResponseObject.class);
- s.alias("Property", Properties.class);
- s.useAttributeFor(ResponseObject.class, "Type");
- s.addImplicitCollection(ParentResponseObject.class, "responseObjects");
- s.addImplicitCollection(ResponseObject.class, "properties");
- s.useAttributeFor(Properties.class, "Name");
- s.useAttributeFor(Properties.class, "Type");
- s.processAnnotations(ParentResponseObject.class);
- ParentResponseObject gh =(ParentResponseObject)s.fromXML(k1);
- System.out.println(gh.toString());
- }
- }
- @XStreamAlias("Objects")
- public class ParentResponseObject {
- @XStreamImplicit
- List<ResponseObject> responseObjects = new ArrayList<ResponseObject>();
- }
- @XStreamAlias("Object")
- public class ResponseObject {
- @XStreamAsAttribute
- String Type;
- @XStreamImplicit
- List<Properties> properties = new ArrayList<Properties>();
- }
- @XStreamAlias("Property")
- @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "Value" })
- public class Properties {
- String Name;
- String Type;
- String Value;
- }
- XStream s = new XStream(new DomDriver());
- s.processAnnotations(ParentResponseObject.class);
- ParentResponseObject gh = (ParentResponseObject) s.fromXML(xml);
- for (ResponseObject o : gh.responseObjects) {
- System.out.println(o.Type);
- for (Properties p : o.properties) {
- System.out.println(p.Name + ":" + p.Type + ":" + p.Value);
- }
- }
Add Comment
Please, Sign In to add comment