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 8108427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:06:21+00:00 2026-06-06T01:06:21+00:00

My Xml Should look like: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <results> <version>1.0</version> <status>ok</status> <lastUpdate>2011-11-21 09:23:59.0</lastUpdate>

  • 0

My Xml Should look like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<results>
<version>1.0</version>
<status>ok</status>
<lastUpdate>2011-11-21 09:23:59.0</lastUpdate>
<total>2</total>
<row>
<areaId></areaId>
<nameEng></nameEng>
<nameGer></nameGer>
</row>
 … more <row></row> blocks …
</results>

How can i achieve this..?
At the moment i have the following.. but i dont know how i can return the album2 to the outputstream as a String…

List<Row> rows = new ArrayList<Row>();

        while(rs.next()){
            int albumId = rs.getInt(1);
            int bookDocId = rs.getInt(2);
            String picUrl = rs.getString(3);
            String descEng = rs.getString(4);
            String descGer = rs.getString(5);

            Row row = new Row();
            row.setAlbumId(albumId);
            row.setBookDocId(bookDocId);
            row.setPicUrl(picUrl);
            row.setDescEng(descEng);
            row.setDescGer(descGer);

            rows.add(row);
        }

        Album album = new Album();
        album.setRows(rows);

        File file = new File("album.xml");
        JAXB.marshal(album, file);

        Album album2 = JAXB.unmarshal(file, Album.class);

        file.deleteOnExit();

EDIT:

@XmlRootElement
public class Album {

    private List<Row> rows = new ArrayList<Row>();

    @XmlElement(name="row")
    public List<Row> getRows(){
        return this.rows;
    }

    public void setRows(List<Row> rows){
        this.rows = rows;
    }

Row.class:

public class Row {
    private int albumId;
    private int bookDocId;
    private String picUrl;
    private String descEng;
    private String descGer; 

    public int getAlbumId() {
        return albumId;
    }
    public int getBookDocId() {
        return bookDocId;
    }
    public String getPicUrl() {
        return picUrl;
    }
    public String getDescEng() {
        return descEng;
    }
    public String getDescGer() {
        return descGer;
    }
    public void setAlbumId(int albumId) {
        this.albumId = albumId;
    }
    public void setBookDocId(int bookDocId) {
        this.bookDocId = bookDocId;
    }
    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }
    public void setDescEng(String descEng) {
        this.descEng = descEng;
    }
    public void setDescGer(String descGer) {
        this.descGer = descGer;
    }
}
}
  • 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-06T01:06:23+00:00Added an answer on June 6, 2026 at 1:06 am

    This is my code, it works well

    @javax.xml.bind.annotation.XmlType
    @javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
    public class Album 
    {
       long version;
    
       String status;
    
       java.util.List<Row> rows;
    
    }  
    
    
    @javax.xml.bind.annotation.XmlType
    @javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
    public class Row 
    {
       String areaId;
    
       String nameEng;
    
       String nameGer;
    }  
    

    Test

    public static void main(final String[] args) throws IOException
       {
          Album al = new Album();
          List<Row> rows = new ArrayList<Row>();
          final Row row1 = new Row();
          row1.areaId = "area1";
          row1.nameEng = "eng1";
          row1.nameGer = "ger1";
          final Row row2 = new Row();
          row2.areaId = "area2";
          row2.nameEng = "eng2";
          row2.nameGer = "ger2";
          rows.add(row2);
          rows.add(row1);
          al.status = "stat";
          al.rows = rows;
          final File file = new File("D:/test.xml");
          final FileOutputStream out = new FileOutputStream(file);
    
          JAXB.marshal(al, out);  
    
          final Album after = JAXB.unmarshal(file, Album.class);
          assert after.status.equals(al.status);
          assert after.rows.size() == al.rows.size();
       }  
    

    You can change access to private and add getters, setters

    To return like String use

      ByteArrayOutputStream output = new ByteArrayOutputStream();
      JAXB.marshal(al, output); 
      output.toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my XML document <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:v="urn:schemas-microsoft-com:vml"> <w:body> <w:p>
I have a XML code like this: <?xml version=1.0 encoding=utf-8 ?> <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml>
I have the following xml: <?xml version=1.0 encoding=UTF-8?> <SomeName> <NodeA> DataA </NodeA> <NodeA> DataB
I have xml similar to the one below: <?xml version='1.0' encoding='utf-8'?> <Document> <name>SMTH</name> <Group>
I need to know how the XML class for the serialization should look like:
My whole app is serving stuff in utf-8, only one page (xml) should return
I have a checkbox that should look like a green light when checked and
My app should look like this: This is how it should look, though the
I would like to add a search bar to my activity that should look
My output xml should be masked with some elements, based on a variable, flag.If

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.