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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:45+00:00 2026-05-28T02:19:45+00:00

I’ve run into a strange problem with JAXB. I’ve used xjc to generate my

  • 0

I’ve run into a strange problem with JAXB. I’ve used xjc to generate my java classes from my XSD and all looks good. If I use schemagen, it produces a proper schema that matches my original xsd. However, if I use JAXBContext.generateSchema(), then the generated schema is incomplete.

I’m using Oracle Java 1.6.0_29 and jaxb-2.2.4-1.jar as the implementation. I’m enclosing the java code (which generates the schema), and the xsd below as well as the output of the jaxb call.

CalculateBorrowingDataResponse.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
    version="1.1"
    attributeFormDefault="unqualified" 
    elementFormDefault="qualified"
    targetNamespace="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse" 
    xmlns:lssSt="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse"
    xmlns:cbdRes="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    <!-- CalculateBorrowingData -->
    <xsd:complexType name="CalculateBorrowingDataResponseType">
        <xsd:sequence>
            <xsd:element name="loanAgmt" type="cbdRes:LoanAgreementType" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>


    <xsd:complexType name="LoanAgreementType">
        <xsd:sequence>
            <xsd:element name="borrowingBasedPmtAmt" type="lssSt:borrowingBasedPmtAmt" minOccurs="0" maxOccurs="1" />
            <xsd:element name="maxPmtAmt" type="lssSt:maxPmtAmt" minOccurs="0" maxOccurs="1" />
            <xsd:element name="borrowingCapacityMin" type="lssSt:borrowingCapacityMin" minOccurs="0" maxOccurs="1" />
            <xsd:element name="borrowingCapacityMax" type="lssSt:borrowingCapacityMax" minOccurs="0" maxOccurs="1" />
            <xsd:element name="propertyValueMinAmt" type="lssSt:propertyValueMinAmt" minOccurs="0" maxOccurs="1" />
            <xsd:element name="propertyValueMaxAmt" type="lssSt:propertyValueMaxAmt" minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="calculateBorrowingDataResponse" type="cbdRes:CalculateBorrowingDataResponseType"/>


    <xsd:simpleType name="borrowingBasedPmtAmt">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="maxPmtAmt">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="borrowingCapacityMin">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="borrowingCapacityMax">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="propertyValueMinAmt">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="propertyValueMaxAmt">
        <xsd:restriction base="xsd:decimal" >
        <xsd:totalDigits value="19" />
        <xsd:fractionDigits value="4" />
        </xsd:restriction>
    </xsd:simpleType>

</xsd:schema>

Java code:

    // Creating the XML tree
    JAXBContext jc = JAXBContext.newInstance( CalculateBorrowingDataResponseType.class );
    Unmarshaller u = jc.createUnmarshaller();

    // generate the schemas
    final List<ByteArrayOutputStream> schemaStreams = new ArrayList<ByteArrayOutputStream>();
    jc.generateSchema(new SchemaOutputResolver(){
        @Override
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            schemaStreams.add(out);
            StreamResult streamResult = new StreamResult(out);
            streamResult.setSystemId("");
            return streamResult;
        }});

    // convert to a list of string
    List<String> schemas = new ArrayList<String>();
    for( ByteArrayOutputStream os : schemaStreams )
    {
        schemas.add(os.toString());
        System.out.println( os.toString());
    }

Output of jaxbContext.generateSchema():

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema elementFormDefault="qualified" version="1.0" targetNamespace="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse" xmlns:tns="http://www.domain.com/ClientServices/LendingSimulation/CalculateBorrowingDataResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="CalculateBorrowingDataResponseType">
    <xs:sequence>
      <xs:element name="loanAgmt" type="tns:LoanAgreementType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="LoanAgreementType">
    <xs:sequence>
      <xs:element name="borrowingBasedPmtAmt" type="xs:decimal" minOccurs="0"/>
      <xs:element name="maxPmtAmt" type="xs:decimal" minOccurs="0"/>
      <xs:element name="borrowingCapacityMin" type="xs:decimal" minOccurs="0"/>
      <xs:element name="borrowingCapacityMax" type="xs:decimal" minOccurs="0"/>
      <xs:element name="propertyValueMinAmt" type="xs:decimal" minOccurs="0"/>
      <xs:element name="propertyValueMaxAmt" type="xs:decimal" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

As you can see, the output schema matches very closely, save and except that it is missing the element definition of calculateBorrowingDataResponse! If I use schemagen, however, the
calculateBorrowingDataResponse element is generated.

Am I missing something in my SchemaOutputResolver setup or doing something incorrect/incomplete? Or is this a bug in the Jaxb RI?

  • 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-05-28T02:19:45+00:00Added an answer on May 28, 2026 at 2:19 am

    Change

    JAXBContext.newInstance(CalculateBorrowingDataResponseType.class);
    

    to

    JAXBContext.newInstance(CalculateBorrowingDataResponseType.class.getPackage().getName());
    

    JAXB needs the information defined in the package-info.java file (generated by xjc from your XSD) inside the above class’ package.

    It doesn’t creates the XSD element in question, because CalculateBorrowingDataResponseType doesn’t have an @XmlRootElement annotation.

    Why didn’t xjc create one from the beginning? See the most authoritative explanation on the Internets regarding this matter.

    And why does your code generates the aforementioned element if you supply a package name to JAXBContext.newInstance(...) even though CalculateBorrowingDataResponseType still missing the @XmlRootAnnotation? I haven’t got the faintest idea! Now I have!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a text area in my form which accepts all possible characters from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.