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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:39:04+00:00 2026-05-16T08:39:04+00:00

I am reading an xml document, inserting an element and then writing it. In

  • 0

I am reading an xml document, inserting an element and then writing it. In this process, the document loses doctype and dtd info. Through “Transformer” class I can set OutputProperties but my requirement is to insert or update some element and not to play with doctype at all.
Could somebody give me a hint?

  • 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-16T08:39:05+00:00Added an answer on May 16, 2026 at 8:39 am

    From a post at Example Depot:

    By default, the DOCTYPE is not written when using a transformer to dump a DOM document to an XML file. This example demonstrates how to write a DOCTYPE with a public and system id. Unfortunately, it is not possible to write a DOCTYPE with an internal DTD.

    The referenced article contains this example.

    Here is another code snippet from someone with the same problem, which, unfortunately is not complete (and the forum is in german language, but the formum text is irrelevant here) but maybe you can complete the missing steps.

    EDIT

    A real ugly hack/workaround – but maybe the only solution to your problem:

    1. Copy the full doctype declaration from the input document to a String
    2. Add a ‘marker comment’ (like <!-- DOCTYPE -->) to the DOM at the very beginning of the document
    3. serialize the document to another String
    4. find and replace the ‘marker comment’ with the saved original doctype declaration
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can Any one help me reading this XML and Looping through <MedicationDispensed> I get
ANSWER FOUND! I'm reading an xml document and I am sending this to a
Background I'm reading and writing an XML document using reader and writer, with filtering
I am reading an xml file using javascript and then I need to submit
I'm reading an XML document using JavaScript & jQuery, and need to extract some
I am reading XML files of Office 2007 document using xquery. In these files
I have the following (highly simplified) XML document that I am reading into my
This is a piece of my XML document: <?xml version=1.0 encoding=UTF-8?> <catalog> <mfVictor> <decal>
Hi I'm reading in an XML document like below <?xml version=1.0 encoding=utf-8?> <ArrayOfSYMBOL xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I'm having an issue reading the below XML document in Chrome - nothing seems

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.