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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:36:38+00:00 2026-06-13T04:36:38+00:00

Before I was using this code to write an XML file using StAX: //

  • 0

Before I was using this code to write an XML file using StAX:

 // Create a XMLOutputFactory
 XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
 // Create XMLEventWriter
 XMLEventWriter eventWriter = outputFactory
        .createXMLEventWriter(new FileOutputStream(behaviorsFilePath));
 // Create a EventFactory
 XMLEventFactory eventFactory = XMLEventFactory.newInstance();
 XMLEvent end = eventFactory.createDTD("\n");
 // Create and write Start Tag
 StartDocument startDocument = eventFactory.createStartDocument();
 eventWriter.add(startDocument);
 eventWriter.add(end);
 eventWriter.add(end);

 // Create config open tag
 StartElement configStartElement = eventFactory.createStartElement("",
          "", ROOT);
//...

This code was working fine but now it throws me an javax.xml.stream.XMLStreamException: Trying to write multiple DOCTYPE declarations exception.

When debugging the application, I am able to see that the exception is thrown when I call the second time: eventWriter.add(end);

Why this code was working before and now it isn’t?

UPDATE:

I’m not sure if this is really important but this code is running in a SwingWorker thread…

The only modification that I made that could be a problem is that I added libraries to the project to use Axis2 Web Services (one of them is: geronimo-stax-api_1.0_spec-1.0.1.jar)… And I saw this:

Speed – Axis2 uses its own object model and StAX (Streaming API for XML) parsing to achieve significantly greater speed than earlier versions of Apache Axis.

And this:

stax-api-1.0.1.jar (The StAX API’s that contain the javax.xml.namespace.QName class. This jar may be replaced by any other jar that contains the javax.xml.namespace.QName implementation. However Axis2 uses this class from the stax-api-1.0.1.jar which comes bundled with the Axis2 distribution)

  • 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-13T04:36:39+00:00Added an answer on June 13, 2026 at 4:36 am

    Because, like the exception tells you already, you are “Trying to write multiple DOCTYPE declarations“. Why does your code have eventWriter.add(end); twice?

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

Sidebar

Related Questions

below is the code i'm using and i've used this 100x's before. And now
I am using this code to write an image to SD after camera.takePicture is
I know we've done this before in another .aspx page that's using this master
Before I decide to use DetailView , I had a url redirect using this
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
This question Check all associations before destroy in rails suggests using :dependent => :restrict
Using a code to convert IList<T> to an FSharpList<T> then write the list values
I'm using the HTML5 FileAPI with Chorome 21 to create, read and modify users.xml
As I understood it before taking this job, XML Uses a series of key-value
I'm using Oracle 11g ( 11.1.0.7.0 ) and I have to create a XML

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.