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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:44:23+00:00 2026-05-29T19:44:23+00:00

I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com

  • 0

I have an XML document that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:msgdata xmlns:xs="http://www.myCompany.com" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.myCompany.com msgdata.xsd">
  <xs:msgid>MsgID001</xs:msgid>
  <xs:msgHash>hlkJKLHljkhkjlHKJLHkjl6y987HJKH</xs:msgHash> 
</xs:msgdata>

A schema document (called msgdata.xsd) was also sent to me. I am using JAXB to unmarshall the above xml document to a Java object.
The unmarshalling code is shown below:

final JAXBContext context = JAXBContext.newInstance(clazz);
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File("C:\\temp\\msgdata.xsd"));

final Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setSchema(schema);

return (T) unmarshaller.unmarshal(new StringReader(xml));  

The target object for the XML is shown below (The object is then converted to a hibernated entity.

@XmlRootElement(name = "msgdata")
public class Message {

    private     String  msgid;
    private     String  msgHash;

    @XmlElement(name = "msgid")
    public String getMsgid() {
        return msgid;
    }

    public void setMsgid(String msgid) {
        this.msgid = msgid;
    }

    @XmlElement(name = "msgHash")
    public String getMsgHash() {
        return msgHash;
    }
    public void setMsgHash(String msgHash) {
        this.msgHash = msgHash;
    }

A couple of questions:

  • I have a rest service where i will receive an XML document in the format shown above. What is the reference for the schema document. I know that the schema document is used for validating the XML document. I think the way it will work is that i use that schema to validate the XML documents that i receive via the REST service. Now the problem is how do i access the schema? Do i just store it somewhere on my file system and access it as shown above?

The XML document has a reference to the schema (See the schemaLocation entry). How will it find the schema document on my file system? Is that schema reference required in the XML document?

  • The XML document as it is now cannot be unmarshalled. When i try to unmarshal it i get the following error:

    Caused by: javax.xml.bind.UnmarshalException: unexpected element
    (uri:”http://www.myCompany.com&#8221;, local:”msgdata”). Expected elements
    are <{}msgdata>
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:120)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1063)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:102)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:150)
    [jaxb-impl-2.2.4.jar:]
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) [xercesImpl-2.9.1.jar:]
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source) [xercesImpl-2.9.1.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:217)
    [jaxb-impl-2.2.4.jar:]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:189)
    [jaxb-impl-2.2.4.jar:]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:136)
    [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:193)
    [jboss-jaxb-api_2.2_spec-1.0.3.Final.jar:1.0.3.Final]
    … 31 more

I thought the namespace is defined in the xml document. I am either not using the schema correctly or the namespace definition is not correct. What am i doing wrong?

Thanks.

  • 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-29T19:44:24+00:00Added an answer on May 29, 2026 at 7:44 pm

    In general, for how to access files (XSD or others) in your Java web application (since you mentioned REST), you could start here. Never rely on absolute paths, for deployment as well as security reasons.

    The xsi schema location attributes are just hints; they are not required. Even if present those don’t have to be considered. For a server side application, I would never use them anyway; one should rely on embedded resources, or use a catalog-like concept at a trusted/secure location.

    The fact that it doesn’t unmarshal, is clear in the error message: it expects a no-namespace element <{}msgdata> as opposed to <{http://www.myCompany.com}msgdata>.

    You need to modify the XML or ammend your class to include things like @XmlElement(name=”…”, namespace=”http://www.myCompany.com”)

    I would say that given schema and XML are correct, your annotations are not in sync.

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

Sidebar

Related Questions

So i have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <gesmes:Envelope
I have an xml document like this: <?xml version=1.0 encoding=UTF-8?> <foo:root xmlns:foo=http://abc.com# xmlns:bar=http://def.com xmlns:ex=http://ex.com>
I have to parse an XML document that looks like this: <?xml version=1.0 encoding=UTF-8
I have an XML document that looks like this: <?xml version=1.0 encoding=utf-8?> <Schema Namespace=EDIManagement.Models.Store
I have a XML document that looks something like this: <?xml version=1.0 encoding=UTF-8?> <citizen>
I have an xml document that looks something like this <?xml version=1.0 encoding=UTF-8?> <mapPoints>
I have a simple xml file that looks like this: <?xml version=1.0 encoding=UTF-8 standalone=yes
I have a XML code like this: <?xml version=1.0 encoding=utf-8 ?> <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml>
I have an xml document that looks like this <?xml version=1.0?> <XML> <VIDEO> <WIDTH>800</WIDTH>
I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley

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.