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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:47:51+00:00 2026-05-23T04:47:51+00:00

I have a XML file, and its xml schema contains couples complexType in it.

  • 0

I have a XML file, and its xml schema contains couples complexType in it. So when I unmarshal the xml file, I want to give the xml parser my xml schema. Is it possible to do it, if so, then how to do it?

EDIT: After I unmarshal, every field in my object is null. Any idea why?

  • 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-23T04:47:52+00:00Added an answer on May 23, 2026 at 4:47 am

    UPDATE

    The issue you are seeing is due to the content being nested within the NameAndAddress element. You could introduce a NameAndAddress class have PackageLabel hold an instance of that.

    PackageLabel

    import java.io.Serializable;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement(name="PackageLabel")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class PackageLabel implements Serializable {
    
        @XmlElement(name="NameAndAddress")
        private NameAndAddress nameAndAddress;
    
    }
    

    NameAndAddress

    import javax.xml.bind.annotation.XmlElement;
    
    public class NameAndAddress {
    
        @XmlElement(name="Name")
        private String name;
    
        @XmlElement(name="Address1")
        private String address1;
    
        @XmlElement(name="Address2")
        private String address2;
    
        @XmlElement(name="City")
        private String city;
    
        @XmlElement(name="State")
        private String state;
    
        @XmlElement(name="ZipCode")
        private String zipCode;
    
    }
    

    EclipseLink JAXB (MOXy)’s @XmlPath Extension

    Alternatively you could use the @XmlPath extension in EclipseLink JAXB (MOXy):

    import java.io.Serializable;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    
    @XmlRootElement(name="PackageLabel")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class PackageLabel implements Serializable {
    
        @XmlPath("NameAndAddress/Name/text()")
        private String name;
    
        @XmlPath("NameAndAddress/Address1/text()")
        private String address1;
    
        @XmlPath("NameAndAddress/Address2/text()")
        private String address2;
    
        @XmlPath("NameAndAddress/City/text()")
        private String city;
    
        @XmlPath("NameAndAddress/State/text()")
        private String state;
    
        @XmlPath("NameAndAddress/ZipCode/text()")
        private String zipCode;
    
    }
    

    For More Information

    • http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
    • http://bdoughan.blogspot.com/2010/07/xpath-based-mapping.html

    You can set an XML schema on an instance of Unmarshaller. This will cause JAXB to validate the input while it converts the XML to objects:

    • http://bdoughan.blogspot.com/2010/12/jaxb-and-marshalunmarshal-schema.html

    If you want to generate an object model from an XML schema, you can also use JAXB to do that:

    • http://bdoughan.blogspot.com/2010/09/processing-atom-feeds-with-jaxb.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 contains its element like <ab:test>Str</ab:test> When I am
I have a big XML file but I do not know its schema. I
I have an XML file and I'm inferring its XSD schema in run-time, using
I have a Silverlight application that reads its content from an XML file. The
I have an XML file and an XML schema in another file and I'd
I have an existing XML schema that contains a type that I would like
What's wrong with the below config file. Its the applicationContex.xml give a syntext error.
I want to read a fairly large xml file. Its small enough to fit
What is the easiest way to convert xml to html? I have xml file
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have

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.