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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:48:44+00:00 2026-06-04T18:48:44+00:00

I am trying to output to XML a table bean with a table name,

  • 0

I am trying to output to XML a table bean with a table name, row count and a list of columns. If I annotate them like attributes, they show:
So this definition:

@XmlRootElement(name = "table")
public class Table {

    private String tableName;
    private int rowCount;
    private List<Column> columnList;

    @XmlAttribute(name = "name")
    public String getTableName() {
        return tableName;
    }

    @XmlAttribute(name = "rowCount")
    public int getRowCount() {
        return rowCount;
    }

    @XmlElement(name = "column")
    public List<Column> getColumnList() {
        return columnList;
    }

}

Outputs this:

    <tables>
     <table name="GGS_MARKER" rowCount="19190">
     <column>
      <columnName>MARKER_TEXT</columnName>
      <datatype>VARCHAR2</datatype>
      <length>4000.0</length>
     </column>
...

But if I change @XmlAttribute with @XmlElement, it just shows:

    <tables>
     <table>
     <column>
      <columnName>MARKER_TEXT</columnName>
      <datatype>VARCHAR2</datatype>
      <length>4000.0</length>
     </column>
...

What should I put in the class to get “name” and “rowcount” as elements?

  • 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-04T18:48:46+00:00Added an answer on June 4, 2026 at 6:48 pm

    All you need to do in your example is change @XmlAttribute to @XmlElement. If as in your post you only have get methods and not set methods you will need to explicitly add the @XmlElement annotation as the default one won’t be applied in this use case (by default all unmapped properties are assumed to have a @XmlElement annotation).

    Table

    package forum10794522;
    
    import java.util.*;
    import javax.xml.bind.annotation.*;
    
    @XmlRootElement(name = "table")
    public class Table {
    
        static Table EXAMPLE_TABLE;
        static {
            EXAMPLE_TABLE = new Table();
            EXAMPLE_TABLE.tableName = "GGS_MARKER";
            EXAMPLE_TABLE.rowCount = 19190;
            List<Column> columns = new ArrayList<Column>(2);
            columns.add(new Column());
            columns.add(new Column());
            EXAMPLE_TABLE.columnList = columns;
        }
    
        private String tableName;
        private int rowCount;
        private List<Column> columnList;
    
        @XmlElement(name = "name")
        public String getTableName() {
            return tableName;
        }
    
        @XmlElement(name = "rowCount")
        public int getRowCount() {
            return rowCount;
        }
    
        @XmlElement(name = "column")
        public List<Column> getColumnList() {
            return columnList;
        }
    
    }
    

    Demo

    package forum10794522;
    
    import javax.xml.bind.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Table.class);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(Table.EXAMPLE_TABLE, System.out);
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <table>
        <column/>
        <column/>
        <rowCount>19190</rowCount>
        <name>GGS_MARKER</name>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate a dynamic xml document in CakePHP to output to
I'm trying to disable log output from all external libraries in logback-test.xml. Somehow it
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
I'm trying to do a easy dynamic <table> with an input XML. My XML
I'm trying to generate an XML output from SQL and need to use a
I'm trying to transform a table to an XML struture and I want one
I am trying to use powershell to convert a csv to an xml table.
I'm trying to return rows in Open XML form from a table value function
I have some XML that stores column information and row data from a table
I'm trying to generate XML that will output the structure and data of any

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.