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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:38:07+00:00 2026-05-28T18:38:07+00:00

I am trying to create java objects from xml file. I am using jaxb(unmarshalling)

  • 0

I am trying to create java objects from xml file. I am using jaxb(unmarshalling) to create java objects.I am getting errors javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"schema"). Expected elements are

I did some google and found out that, we need xsd file to do that… so I converted it to xsd using apache inst2xsd tool. I am using following java code:

import java.io.FileNotFoundException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="report")
public class Report 
{
    public static void main(String [] args) throws FileNotFoundException
    {
        try
        {
            JAXBContext jc = JAXBContext.newInstance(new Class[] {com.bcbsks.testjb.Report.class});             
            Unmarshaller um = jc.createUnmarshaller();          
            Report myJAXBObject = (Report)um.unmarshal(new java.io.FileInputStream("report.xsd"));
        } 
        catch( UnmarshalException ue ) 
        {    
            ue.printStackTrace(); 
        } 
        catch( JAXBException je ) 
        { 
            je.printStackTrace(); 
        } 
    }
}

But I am getting fol;owing error:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.w3.org/2001/XMLSchema", local:"schema"). Expected elements are  (none)

Can you please tell me whats wrong I am doing?

Any help is greatly appreciated.

  • 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-28T18:38:08+00:00Added an answer on May 28, 2026 at 6:38 pm

    I think you are missing a few steps. You didn’t post what report.xsd is, nor a sample xml, so I’m going to take a few guesses.

    For starters, you are trying to unmarshal the xsd and not xml, which is itself the root of the problem. That being said, your Report.java class does not look properly generated so it is unlikely that your unmarshalling would work even if you tried against your xml file.

    If you have a properly created XSD file, the first thing you should do is create the JaxB POJOs using xjc. xjc comes installed with java, and you use it to create annotated java classes from the xsd. It will also create 2 additional files – ObjectFactory.java and package-info.java which are used by JAXB. (You can specify the output path using the -d param (see –help for the full list of switches)

    xjc -d c:\dev\myproject\src\main\java report.xsd
    

    Once you have those files generated, you have to create your JAXBContext based on that package/file.

    JAXBContext jc = JAXBContext.newInstance(something.generated.Report.class);             
    Unmarshaller um = jc.createUnmarshaller();          
    Report myJAXBObject = (Report)um.unmarshal(new java.io.FileInputStream("report.xsd"), Report.class).getValue();
    

    The unmarshaller generates a JAXBElement, from which you can extract the actual report class.

    Hope this helps.

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

Sidebar

Related Questions

I'm trying to create a Qt main windows from Java using JNI directly and
I'm trying to create a zip file from a directory in Java, then place
I'm trying create an immutable object and initialise it from xml config file in
I'm trying to use JAXB to unmarshal this file into Java objects. I know
I am trying to unmarshall data from an XML object in Java using SimpleXML.
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I am using Java 6 and am trying to create an HttpsURLConnection against a
I am trying to create my first GUI application using (Java + Eclipse +
I am trying to create a generic class to write and read Objects to/from
I am trying to create a browser based application that can access Java Objects

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.