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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:31:23+00:00 2026-06-07T18:31:23+00:00

JAXB can only unmarshall an XML if the soap envelope has already been removed.

  • 0

JAXB can only unmarshall an XML if the soap envelope has already been removed. However, the SOAP response I’m trying to unmarshall has its namespace declaration on the soap envelope. If I remove the soap envelope, the namespace declaration will also be removed. As such the prefix of the tags will be referring to none. This causes JAXB to throw an error. How can I unmarshall a SOAP response using JAXB if the namespace is declared on the SOAP envelope?

A similar sample of the XML that I need to unmarshall is below:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://example.com/">
    <soapenv:Body>
        <ns:getNumberResponse>
            <number>123456789</number>
        </ns:getNumberResponse>
    </soapenv:Body>
</soapenv:Envelope>

This is what happens if I remove the soap envelope:

<ns:getNumberResponse>
    <number>123456789</number>
</ns:getNumberResponse>

If I removed the soap envelope, the namespace declaration will also be gone. JAXB won’t be able to unmarshall the above xml because the namespace definition for the prefix “ns” is missing. As such it will return a "The prefix "ns" for element "ns:getNumberResponse" is not bound." error message. How do I fix it?

Please note that I’m using JDK 1.5. I’m not sure if there is a way to solve this in JDK 1.6. I was able to use JAXB because I downloaded the required jars for using JAXB.

  • 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-06-07T18:31:24+00:00Added an answer on June 7, 2026 at 6:31 pm

    You can use a StAX parser to parse the SOAP message and then advance the XMLStreamReader to the getNumberResponse element and use the unmarshal method that takes a class parameter. A StAX parser is included in Java SE 6, but you will need to download one for Java SE 5. Woodstox is a popular StAX parser.

    Response

    package forum11465653;
    
    public class Response {
    
        private long number;
    
        public long getNumber() {
            return number;
        }
    
        public void setNumber(long number) {
            this.number = number;
        }
    
    }
    

    Demo

    An XMLStreamReader has a NamespaceContext. The NamespaceContext knows all the active namespace declarations for the current level. Your JAXB (JSR-222) implementation will be able to leverage this to get the necessary information.

    package forum11465653;
    
    import java.io.FileReader;
    import javax.xml.bind.*;
    import javax.xml.stream.*;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception{
            XMLInputFactory xif = XMLInputFactory.newFactory();
            XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("src/forum11465653/input.xml"));
            xsr.nextTag(); // Advance to Envelope tag
            xsr.nextTag(); // Advance to Body tag
            xsr.nextTag(); // Advance to getNumberResponse tag
            System.out.println(xsr.getNamespaceContext().getNamespaceURI("ns"));
    
            JAXBContext jc = JAXBContext.newInstance(Response.class);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            JAXBElement<Response> je = unmarshaller.unmarshal(xsr, Response.class);
            System.out.println(je.getName());
            System.out.println(je.getValue());
        }
    
    }
    

    Output

    http://example.com/
    {http://example.com/}getNumberResponse
    forum11465653.Response@781f6226
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JAXB 2.0 JDK 6 in order to unmarshall an XML instance
JAXB Generated classes only capture the structural information from the XML schema that is
I use Jersey with JAXB to convert my response to XML. I have several
I'm trying to use JAXB to pull some elements from a large XML file
I was trying to add the XML schema to an existing EJB project. JAXB
How can I get jaxb to bind to my Vector? I cannot seem to
Anyone can tell me which one is better (JAXB or Apache XMLBeans) taking in
At http://jaxb.java.net/ it says JAXB its under dual license consisting of the CDDL v1.0
I am trying to use JAXB's introspection to marshall and unmashall some existing domain
I am trying to use the Jaxb classes generator in eclipse to generate jaxb

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.