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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:10:09+00:00 2026-05-24T02:10:09+00:00

1.) I have an XSD file (I have no control over) that I converted

  • 0

1.) I have an XSD file (I have no control over) that I converted to object model using JAXB

2.) I have a database extract in XML format. The XML element tag names are strictly the field names of the table

3.) I mapped the xml elements to the Java class using annotations.

Question: Is there a way to maintain the element names in the XSD file, and JUST extract the value of the xml elements.

JAXB annotated class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Item", propOrder = {
    "code",
    "name",
    "price"
})
@XmlRootElement(name="inventory")
public class Item {

    @XmlElement(name="catalog_num", required = true)
    protected String code;

    @XmlElement(name="catalog_descrip", required = true)
    protected String name;

    @XmlElement(name="prod_price")
    protected double price;


    public String getCode() {
        return code;
    }
//etc

An excerpt of the database xml file:

<?xml version="1.0"?>
<inventory>
          <catalog_num>I001</catalog_num>
          <catalog_descrip>Descriptive Name of Product</catalog_descrip>
          <prod_price>11200</prod_price>
</inventory>

The result I need to get after marshaling the above xml file is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Item>
    <code>I001</code>
    <name>Descriptive Name of Product</name>
    <price>11200.0</price>
</Item>

In the above code, I have tried annotating the methods instead of the fields, but I yield the same result. I just want the value extracted from the xml elements, but not change the element names.

I hope I am making sense.

  • 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-24T02:10:10+00:00Added an answer on May 24, 2026 at 2:10 am

    Note: I’m the EclipseLink JAXB (MOXy) lead, and a member of the JAXB (JSR-222) expert group.

    MOXy offers an extension where you can apply a second XML binding via an XML document. This binding document can either be used to add metadata, or when xml-mapping-metadata-complete="true" completely replace the metadata supplied by the JAXB annotations on the Java model;

    <?xml version="1.0"?>
    <xml-bindings
        xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
        package-name="forum6838882" 
        xml-mapping-metadata-complete="true">
        <java-types>
            <java-type name="Item" xml-accessor-type="FIELD">
                <xml-root-element name="Item"/>
            </java-type>
        </java-types>
    </xml-bindings>
    

    The bindings file is passed as a parameter when creating the JAXBContext:

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "forum6838882/binding.xml");
    JAXBContext resultJC = JAXBContext.newInstance(new Class[] {Item.class}, properties);
    

    To solve your issue you could create one JAXBContext to handle the database document (using the annotated classes), and create a second JAXBContext to handle the result format using the MOXy binding file. Below is how this would look:

    package forum6838882;
    
    import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    import javax.xml.bind.Unmarshaller;
    
    import org.eclipse.persistence.jaxb.JAXBContextFactory;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext databaseJC = JAXBContext.newInstance(Item.class);
            Unmarshaller databaseUnmarshaller = databaseJC.createUnmarshaller();
            File databaseXML = new File("src/forum6838882/database.xml");
            Item item = (Item) databaseUnmarshaller.unmarshal(databaseXML);
    
            Map<String, Object> properties = new HashMap<String, Object>();
            properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "forum6838882/binding.xml");
            JAXBContext resultJC = JAXBContext.newInstance(new Class[] {Item.class}, properties);
            Marshaller resultMarshaller = resultJC.createMarshaller();
            resultMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            resultMarshaller.marshal(item, System.out);
        }
    }
    

    For a More Detailed Example See:

    • http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html
    • 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 generated an XSD file from an XML snippet using xsd.exe /out What
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 XSD file that is encoded in UTF-8, and any text editor
I am working on Jboss 4.05 , I have an xsd file that was
I have created a C# class file by using a XSD-file as an input.
I have this Maven task to generate Java classes from an XSD file using
I have an XML Schema Definition file .XSD who's elements are in Spanish. I
So here's the scenario...I have an XSD file describing all the objects that I

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.