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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:21:31+00:00 2026-05-24T22:21:31+00:00

When I marshal Java objects into XML, some extra characters are added after the

  • 0

When I marshal Java objects into XML, some extra characters are added after the closing of the root tag.

Here is how I save the resulting java objects after unmarshaling from XML into a file:

public void saveStifBinConv(ConversionSet cs, String xmlfilename) {
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(xmlfilename);
        this.marshaller.marshal(cs, new StreamResult(os));
    }
    catch (IOException e) {
        log.fatal("IOException when marshalling STIF Bin Conversion XML file");
        throw new WmrFatalException(e);
    }
    finally {
        if (os != null) {
            try {
                os.close();
            }
            catch (IOException e) {
                log.fatal("IOException when closing FileOutputStream");
                throw new WmrFatalException(e);
            }
        }
    }
}

The extra characters are padded after closing tag of the root tag.

The characters added are some of the characters from the XML. Example: tractor-to-type><bin-code>239</bin-code><allowed>YES</allowed></extractor-to></extractor-mapping><extractor-mapping><e

I use Spring OXM’s Jaxb2Marshaller and JAXB 2.

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-24T22:21:33+00:00Added an answer on May 24, 2026 at 10:21 pm

    This is because I do 2 steps in saving the XML:

    1. marshal the XML to a FileOutputStream, resulting in an XML file
    2. then open a FileInputStream on the XML file in step 1 and write the FileInputStream to a ServletOutputStream

    There must be a buffer underflow happening.

    Solution

    Marshal the XML directly to a ServletOutputStream (for web user to download the XML file).

            JAXBContext jc = JAXBContext.newInstance(pkg);
            Marshaller m = jc.createMarshaller();
            m.marshal(cs, os);
    

    where os is a ServletOutputStream.

        //return an application file instead of html page
        response.setContentType("text/xml");//"application/octet-stream");
        response.setHeader("Content-Disposition", "attachment;filename="
            + xmlFilename);
    
        OutputStream out = null;
        out = response.getOutputStream();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to marshall Java objects into XML and vice-versa from within an
I'm using Castor to marshal/unmarshal my Java objects, one of which contains an EnumMap.
I'm looking for a Java library that would allow me to marshal XML to
Im working on a java project where i need to read some objects from
I'm new to JAXB and I want to marshal and un-marshal XML/Objects to Objects/XML.
I am working in an application where we need to save objects in XML
I have a Java application that I want to save the data in XML
I need to query XML out of a MarkLogic server and marshal it into
We're using the DTO pattern to marshal our domain objects from the service layer
Here is a C# program that tries Marshal.SizeOf on a few different types: using

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.