Reading XML value to populate Java variable

zoe

New Member
I am working with xstream to convert some XML into Java objects. The XML pattern is of the below format:\[code\]<Objects> <Object Type="System.Tuning" >4456</Object> <Object Type="System.Lag" >7789</Object> </Objects>\[/code\]Basically the parent Objects tag can have n number of Object tags. For this I have modelled my class like this:\[code\]class ParentResponseObject { List <ResponseObject>responseObjects = new ArrayList<ResponseObject>(); public ParentResponseObject() { // TODO Auto-generated constructor stub }}class ResponseObject { String Type; String Value; public ResponseObject() { }}\[/code\]And finally I am using the below code to populate my java class:\[code\]XStream s = new XStream(new DomDriver()); s.alias("Objects", src.core.PowerShell.MyAgain.ParentResponseObject.class); s.alias("Object", src.core.PowerShell.MyAgain.ResponseObject.class); s.useAttributeFor(src.core.PowerShell.MyAgain.ResponseObject.class, "Type"); s.addImplicitCollection(src.core.PowerShell.MyAgain.ParentResponseObject.class, "responseObjects"); ParentResponseObject gh =(ParentResponseObject)s.fromXML(k1);\[/code\]Using the \[code\]useAttribute\[/code\] method I am able to read the "Type" attribute of Object Type, but how do I read the values within tags like 4456, 7789 and populate it in the variable \[code\]ResponseObject\[/code\].value.
 
Back
Top