Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:24:47+00:00 2026-06-12T03:24:47+00:00

I am working with xstream to convert some XML into Java objects. The XML

  • 0

I am working with xstream to convert some XML into Java objects. The XML pattern is of the below format:

<Objects>   
<Object Type="System.Tuning" >4456</Object> 
<Object Type="System.Lag" >7789</Object>    
</Objects>

Basically the parent Objects tag can have n number of Object tags. For this I have modelled my class like this:

class ParentResponseObject {    
    List <ResponseObject>responseObjects = new ArrayList<ResponseObject>();
    public ParentResponseObject() {
        // TODO Auto-generated constructor stub
    }
}
class ResponseObject {
       String Type;
       String Value;
    public ResponseObject() {

    }
}

And finally I am using the below code to populate my java class:

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);

Using the useAttribute 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 ResponseObject.value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:24:48+00:00Added an answer on June 12, 2026 at 3:24 am

    You need to use the ToAttributedValueConverter. It is easy to do this using xstream annotations as shown below:

    @XStreamAlias("Object")
    @XStreamConverter(value = ToAttributedValueConverter.class, strings = { "value" })
    public class ResponseObject {
    
        @XStreamAlias("Type")
        private String type;
    
        private String value;
    
        public ResponseObject() {
        }
    
        public String getType() {
            return type;
        }
    
        public String getValue() {
            return value;
        }
    }
    

    @XStreamAlias("Objects")
    public class ParentResponseObject {
    
        @XStreamImplicit
        private final List <ResponseObject> responseObjects = new ArrayList<ResponseObject>();
    
        public ParentResponseObject() {
        }
    
        public List<ResponseObject> getResponseObjects() {
            return responseObjects;
        }
    }
    

    Main method:

    XStream xStream = new XStream();
    xStream.processAnnotations(ParentResponseObject.class);
    ParentResponseObject parent = (ParentResponseObject)xStream.fromXML(file);
    for (ResponseObject o : parent.getResponseObjects()) {
        System.out.println(o.getType() + ":" + o.getValue());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with xstream to read some xml in the following format --
I'm working with a system that generates this type of XML: <address> <addressLine>123 Main
I am using Xstream to serializing a Job object. It looks working fine. but
I am working to parse XML data in a java web application on Google
Working on game where plates will be falling from top to bottom. Some plates
Working with a Lucene index, I have a standard document format that looks something
Working in Java: I have a JFrame class, and separate classes for my two
I am currently deserializing JSON using XStream, and it has been working great. However,
Working on an app using Akka 2 deployed with Play-mini. I pulled logback into
Working in Scala-IDE, I have a Java library, in which one of the methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.