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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:59:45+00:00 2026-05-26T04:59:45+00:00

I have a XML and XSD file corresponds to it. I have just started

  • 0

I have a XML and XSD file corresponds to it. I have just started to learn Spring Framework and I use Spring 3. I should write a code that takes that XML file and assigns it to an object at Java. I searched about it but how can I do it with using Spring (maybe some useful tricks or anything else?)

  • 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-26T04:59:46+00:00Added an answer on May 26, 2026 at 4:59 am

    I recently used Spring OXM & JAXB for that. The class is org.springframework.oxm.jaxb.Jaxb2Marshaller. You can, ofcourse, use any other implementation of org.springframework.oxm.Unmarshaller.

    But first You’ll need to generate the objects based on Your XSD. For that I used maven-jaxb2-plugin.

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
            <execution>
                <id>generate-oxm</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaDirectory>src/main/resources/META-INF/xsd</schemaDirectory>
                    <generatePackage>com.stackoverflow.xjc</generatePackage>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    And then configure the marshaller:

    @Configuration
    public class ApplicationConfiguration {
    
        @Autowired
        private ResourcePatternResolver resourceResolver;
    
        @Bean
        public Jaxb2Marshaller oxmMarshaller() throws IOException {
            Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
            marshaller.setContextPath("com.stackoverflow.xjc");
            marshaller.setSchemas(resourceResolver.getResources("classpath:/META-INF/xsd/*.xsd"));
            return marshaller;
        }
    }
    

    Than just:

    File xmlFile = new File("my.xml");
    Source source = new StreamSource(new FileInputStream(xmlFile));
    JAXBElement<MyXmlRootElemClass> result = oxmMarshaller.unmarshal(source);
    MyXmlRootElemClass theObject = result.getValue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that I used to create an XSD File and
I have been provided an XSD and a sample Xml file that contains the
I want to write an XML file. I have created an XSD file named
I have this code to validate an XML file against an XSD file: $file
I have an XML file that I'm trying to validate against an XSD file
I have an XML file that is validated against an XSD file. When a
I have an XML Schema Definition file .XSD who's elements are in Spanish. I
I have an xml message that is in the older schema (xsd) format. My
I have an XML structure that is 4 deep: <?xml version=1.0 encoding=utf-8?> <EmailRuleList xmlns:xsd=EmailRules.xsd>
I have a XML file and a a bunch of XSD files with schemas.

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.