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

  • Home
  • SEARCH
  • 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 9199749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:36:23+00:00 2026-06-17T22:36:23+00:00

I am expecting a XML generated by JAXB which has the following pattern: <payload>

  • 0

I am expecting a XML generated by JAXB which has the following pattern:

<payload>
   <parameters>
      <paramName>clientAssocIds</paramName>
      <paramVal>0207</paramVal>
      <paramName>quoteType</paramName>
      <paramVal>NTB</paramVal>
      <paramName>quoteDateLimitDays</paramName>
      <paramVal>365</paramVal>
      <paramName>externalIndicator</paramName> 
      <paramVal>1</paramVal>
   </parameters>
</payload>

The <paramName> and <paramVal> are name and value pairs, which means <paramVal> has to follow <paramName>.

I wrote a XML Schema and use JAXB to generate the java class based on this schema, then I set all the values and marshalled the class, it didn’t generate the xml pattern I expected above.

Here is my schema:

<xsd:complexType name="sgrpCommonMessage">
  <xsd:sequence>
    <xsd:element name="payload" type="payload" />
  </xsd:sequence>
</xsd:complexType>



<xsd:complexType name="payload">
  <xsd:sequence>
    <xsd:choice minOccurs="0" maxOccurs="1">
        <xsd:element name="parameters" type="parameter" />
    </xsd:choice>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="parameter">
  <xsd:sequence>
    <xsd:element minOccurs="0" name="paramName" type="xsd:string" />
    <xsd:element minOccurs="0" name="paramVal" type="xsd:string" />
  </xsd:sequence>
</xsd:complexType>

And the generated xml has a few <parameters>, which is not what I expect. I want to wrap all the <paramName> and <paramVal> pairs in one <parameters>:

<payload>
  <parameters>
    <paramName>quoteDateLimitDays</paramName>
    <paramVal>NTB</paramVal>
  </parameters>
  <parameters>
    <paramName>clientAssocIds</paramName>
    <paramVal>0207</paramVal>
  </parameters>
  <parameters>
    <paramName>quoteType</paramName>
    <paramVal>NTB</paramVal>
  </parameters>
  <parameters>
    <paramName>externalIndicator</paramName>
    <paramVal>NTB</paramVal>
  </parameters>
</payload>

I am wondering if JAXB is capable of realizing such XML structure, if not, what API should I use, if yes, how?

  • 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-17T22:36:24+00:00Added an answer on June 17, 2026 at 10:36 pm

    You could have an XML schema like the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
        <xsd:element name="parameters" type="parameters" />
    
        <xsd:complexType name="parameters">
            <xsd:sequence minOccurs="0" maxOccurs="unbounded">
                <xsd:element name="paramName" type="xsd:string" />
                <xsd:element name="paramValue" type="xsd:string" />
            </xsd:sequence>
        </xsd:complexType>
    
    </xsd:schema>
    

    Then with the generated model you could do:

    import javax.xml.bind.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance("forum14571803");
    
            ObjectFactory objectFactory = new ObjectFactory();
    
            Parameters parameters = objectFactory.createParameters();
            parameters.getParamNameAndParamValue().add(objectFactory.createParametersParamName("A"));
            parameters.getParamNameAndParamValue().add(objectFactory.createParametersParamValue("a"));
            parameters.getParamNameAndParamValue().add(objectFactory.createParametersParamName("B"));
            parameters.getParamNameAndParamValue().add(objectFactory.createParametersParamValue("b"));
    
            JAXBElement<Parameters> root = objectFactory.createParameters(parameters);
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.marshal(root, System.out);
        }
    
    }
    

    Which would give you the following output:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <parameters>
        <paramName>A</paramName>
        <paramValue>a</paramValue>
        <paramName>B</paramName>
        <paramValue>b</paramValue>
    </parameters>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML: <TRUCK Counter=0> <CARRIER>A PLUS EXPEDITING &amp; LOGISTICS INC.</CARRIER> <CARRIERPHONE>(000)000-0220</CARRIERPHONE>
I was expecting the following code to throw an exception when I goto write
I've got an XSD schema which I've generated a class for using xsd.exe, and
For a REST service I define the necessary DTOs in XML to generate JAXB
I'm working on an application that uses XSLT to transform XML generated by JSP.
I am having troubles reading XML, I followed this tutorial , and generated the
I have the following xml: <root> <text><![CDATA[ОПЕЛХМЮБЮ ОПЕГ БЗПРЪЫ ЯЕ АЮПЮАЮМ, Б ЙНИРН ЯЕ]]></text>
In short; i have many empty lines generated in an XML file, and i
When I read an xml file into a dataset, if the root node has
I have generated an XSD file for an XML file and it's working when

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.