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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:49:48+00:00 2026-05-31T20:49:48+00:00

I have some problem when unmarshaling a .xml at a web service using JAXB.

  • 0

I have some problem when unmarshaling a .xml at a web service using JAXB.

This is the .xml file being sent from some client to the web service.

<?xml version="1.0" encoding="UTF-8"?>
<PERSON xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="file:/D:/MyWorkSpace/JAVA%20WEB%20Services%20DEVELOPER/XML%20Workspace/Persons.xsd">
    <NAME>Michael</NAME>
    <AGE>12</AGE>
    <ADRESS>
        <STREET>Somewhere in Spain</STREET>
        <ZIP>47015</ZIP>
    </ADRESS>
    <HOBY indoorHoby="true"/>
</PERSON>

This is the method that does the unmarshaling

    @POST
    @Path("/XMLArrivalBeacon")
    @Consumes(MediaType.APPLICATION_XML)
    public Response methodI(String content) {
        System.out.print(content);
        try {
            //Unmarshaling            
            JAXBContext context = JAXBContext.newInstance(Person.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            //Unmarshal the String
            Person person = (Person) unmarshaller.unmarshal(new StreamSource(new StringReader(content)));
            //Checking that the values were recieved ok
            System.out.print(person.getName());
            return Response.ok("XML recieved from client!!!").build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

Here is the person class annotated with the JAXB annotations(Was automatically generated from the Schema)

package bindedschemas;

import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="age">
 *           &lt;simpleType>
 *             &lt;restriction base="{http://www.w3.org/2001/XMLSchema}integer">
 *               &lt;minInclusive value="18"/>
 *             &lt;/restriction>
 *           &lt;/simpleType>
 *         &lt;/element>
 *         &lt;element name="address">
 *           &lt;complexType>
 *             &lt;complexContent>
 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *                 &lt;sequence>
 *                   &lt;element name="street" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *                   &lt;element name="zip" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *                 &lt;/sequence>
 *                 &lt;attribute name="country" type="{http://www.w3.org/2001/XMLSchema}string" />
 *               &lt;/restriction>
 *             &lt;/complexContent>
 *           &lt;/complexType>
 *         &lt;/element>
 *         &lt;element name="hobie">
 *           &lt;simpleType>
 *             &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
 *             &lt;/restriction>
 *           &lt;/simpleType>
 *         &lt;/element>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "name",
    "age",
    "address",
    "hobie"
})
@XmlRootElement(name = "Person")
public class Person {

    @XmlElement(required = true)
    protected String name;
    @XmlElement(required = true)
    protected BigInteger age;
    @XmlElement(required = true)
    protected Person.Address address;
    @XmlElement(required = true)
    protected String hobie;

    /**
     * Gets the value of the name property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the value of the name property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setName(String value) {
        this.name = value;
    }

    /**
     * Gets the value of the age property.
     * 
     * @return
     *     possible object is
     *     {@link BigInteger }
     *     
     */
    public BigInteger getAge() {
        return age;
    }

    /**
     * Sets the value of the age property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setAge(BigInteger value) {
        this.age = value;
    }

    /**
     * Gets the value of the address property.
     * 
     * @return
     *     possible object is
     *     {@link Person.Address }
     *     
     */
    public Person.Address getAddress() {
        return address;
    }

    /**
     * Sets the value of the address property.
     * 
     * @param value
     *     allowed object is
     *     {@link Person.Address }
     *     
     */
    public void setAddress(Person.Address value) {
        this.address = value;
    }

    /**
     * Gets the value of the hobie property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getHobie() {
        return hobie;
    }

    /**
     * Sets the value of the hobie property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setHobie(String value) {
        this.hobie = value;
    }


    /**
     * <p>Java class for anonymous complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType>
     *   &lt;complexContent>
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
     *       &lt;sequence>
     *         &lt;element name="street" type="{http://www.w3.org/2001/XMLSchema}string"/>
     *         &lt;element name="zip" type="{http://www.w3.org/2001/XMLSchema}string"/>
     *       &lt;/sequence>
     *       &lt;attribute name="country" type="{http://www.w3.org/2001/XMLSchema}string" />
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "street",
        "zip"
    })
    public static class Address {

        @XmlElement(required = true)
        protected String street;
        @XmlElement(required = true)
        protected String zip;
        @XmlAttribute(name = "country")
        protected String country;

        /**
         * Gets the value of the street property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getStreet() {
            return street;
        }

        /**
         * Sets the value of the street property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setStreet(String value) {
            this.street = value;
        }

        /**
         * Gets the value of the zip property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getZip() {
            return zip;
        }

        /**
         * Sets the value of the zip property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setZip(String value) {
            this.zip = value;
        }

        /**
         * Gets the value of the country property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getCountry() {
            return country;
        }

        /**
         * Sets the value of the country property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setCountry(String value) {
            this.country = value;
        }

    }

}

And this is the exception i get

SEVERE: javax.xml.bind.UnmarshalException: unexpected element (uri:””,
local:”PERSON”). Expected elements are <{}Person> at
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
at
com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)

Any idea how can i fix it?

  • 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-31T20:49:49+00:00Added an answer on May 31, 2026 at 8:49 pm

    Your xml does not match your schema. xml element names are case sensitive. “PERSON” and “Person” are not the same element.

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

Sidebar

Related Questions

I have some problem with calling web service from flex. I have service with
I have some problem with replace command. Input file i have this {a[$1]=a[$1]FS$2}END{for(i in
I have some problem with using jstl. I have this: <jsp:useBean id=view class=user.View></jsp:useBean> <jsp:useBean
I have some problem while trying to use the schemagen tool from JAXB library
I have some problem to compare values from different array list From this values,
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
I have some problem with my .htaccess file. Here I am adding my problem.
I have some problem to order an array by a field of this, here
I have some problem with inserting image when i generate pdf using FPDF library
i have some problem. when i run this project, only messagebox button ok appear,

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.