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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:07:19+00:00 2026-05-28T13:07:19+00:00

I get the following exception when I attempt to unmarshall XML back into java

  • 0

I get the following exception when I attempt to unmarshall XML back into java code. It seems like I am missing the namespace declaration somewhere, but I am not sure where.

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"wg_provider").
Expected elements are <{http://www.warriorgateway.org/WGProvider.xsd}wg_provider>

This file was originally created with a JAXB marshaller here:

    JAXBContext providerContext = JAXBContext.newInstance(WgProvider.class);
    Marshaller providerMarshaller = providerContext.createMarshaller();
    providerMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter providerWriter = new StringWriter();
    providerMarshaller.marshal(provider, providerWriter);

Here is the top of the Schema file:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.warriorgateway.org/WGProvider.xsd"
    xmlns:ns1="http://www.warriorgateway.org/WGProvider.xsd"
    elementFormDefault="qualified">

    <xsd:element name="wg_provider">
        <xsd:complexType>

Here is the the top of the XML file to be unmarshalled:

<?xml version="1.0" encoding="UTF-8"?>
<wg_provider xmlns="http://www.warriorgateway.org/WGProvider.xsd">
    <ein>26-0081701</ein>
    <name>MOMS CLUB</name>
    <is_virtual>false</is_virtual>
    <description>
</description>

Here is the top of the JAXB generated Java file:

@XmlRootElement(name = "wg_provider" )
public class WgProvider {

I tried adding the namespace element to the Annotation but it made no difference.

Here is the package-info.xml content:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.warriorgateway.org/WGProvider.xsd", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package org.warriorgateway.api.model.wg;

And finally here is the unmarshalling code:

for (String wrappedProviderXML : wrappedProviderXMLList) {

    DocumentBuilderFactory documentbuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentbuilder = documentbuilderFactory.newDocumentBuilder();
    ByteArrayInputStream xmlStream = new ByteArrayInputStream(wrappedProviderXML.getBytes());
    Document providerXMLDocument = documentbuilder.parse(xmlStream);

    JAXBContext wgProviderContext;
    try {
        wgProviderContext = JAXBContext.newInstance(WgProvider.class);
        Unmarshaller wgProviderUnmarshaller = wgProviderContext.createUnmarshaller();

        WgProvider wgProvider = (WgProvider) wgProviderUnmarshaller.unmarshal(providerXMLDocument);
    } catch (JAXBException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }

Thanks-in-advance,

Guido

P.S. I am using Netbeans 7 to generate the bindings.

  • 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-28T13:07:19+00:00Added an answer on May 28, 2026 at 1:07 pm

    In your sample you need to set your DocumentBuilderFactory to be namespace aware:

    DocumentBuilderFactory documentbuilderFactory = DocumentBuilderFactory.newInstance();
    documentbuilderFactory.setNamespaceAware(true);
    

    You could also unmarshal the ByteArrayInputStream directly:

    unmarshaller.unmarshal(xmlStream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following Exception running my app: java.net.SocketException: Permission denied (maybe missing INTERNET
I get the following error when I run a java program: Exception in thread
For the attached code, I get the following compile time error : exception during
When I run the following code, I get the exception below: ''# NOTE: ExcelApp
I get the following exception when trying to access any nodes of a parsed
I seemed to get the following exception when trying to deploy my application: Caused
I get the following error: Unhandled Exception: System.IO.IOException: The parameter is incorrect. at System.IO.__Error.WinIOError(Int32
The following WMI query throws an exception at serverProtocolsManagement.Get() when sqlHost is an invalid
When I execute the following query, I get an exception telling me that 'feedItemQuery'
With my Ruby script: imap = Net::IMAP.new('imap.gmail.com') imap.login(some_email@host.com, password) I get the following exception:

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.