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

  • Home
  • SEARCH
  • 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 7608251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:52:08+00:00 2026-05-31T00:52:08+00:00

When I marshal an XML with this attribute marshal.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); it will

  • 0

When I marshal an XML with this attribute

marshal.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

it will generate an empty line break at the very top

//Generate empty line break here    
<XX>
    <YY>
        <PDF>pdf name</PDF>
        <ZIP>zip name</ZIP>
        <RECEIVED_DT>received date time</RECEIVED_DT>
    </YY>
</XX>

I think the reason is because marshal.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);, which remove <?xml version="1.0" encoding="UTF-8" standalone="yes"?>, leave the output xml a line break in the beginning. Is there a way to fix this? I use JAXB come with JDK 6, does Moxy suffer from this problem?

  • 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-31T00:52:09+00:00Added an answer on May 31, 2026 at 12:52 am

    As you point out EclipseLink JAXB (MOXy) does not have this problem so you could use that (I’m the MOXy lead):

    • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html

    Option #1

    One option would be to use a java.io.FilterWriter or java.io.FilterOutputStream and customize it to ignore the leading new line.

    Option #2

    Another option would be to marshal to StAX, and use a StAX implementation that supports formatting the output. I haven’t tried this myself but the answer linked below suggests using com.sun.xml.txw2.output.IndentingXMLStreamWriter.

    • https://stackoverflow.com/a/3625359/383861
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JAXBContext context = JAXBContext .newInstance(CreateExemptionCertificate.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(cc, System.out); In
I am using JAXB XMLadapter to marshal and unmarshal Boolean values. The application's XML
I want to marshal many objects into a single xml file. This is going
I'm struggling with the few problems marshal/unmarshall JSon and it looks i will never
I'm trying to marshal a sub-class as super-class with xsi:type information as the XML
I have a string of XML that looks like this: <e1 atr1=3 atr2=asdf> <e1b
This code: println(new XStream.toXML(List(1,2,3))) produces this XML: <scala.coloncolon serialization=custom> <unserializable-parents/> <scala.coloncolon> <int>1</int> <int>2</int> <int>3</int>
I have a servlet which uses JAXB to unmarhsal and marshal an XML file,
I have an object x which I want to marshal into a file. xml
I'm generating OpenOffice XML using JAXB, and need to apply an xml:space=preserve attribute to

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.