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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:11:50+00:00 2026-05-17T21:11:50+00:00

I have code that creates an XML document that is difficult to read in

  • 0

I have code that creates an XML document that is difficult to read in a basic text editor. I tried using transformer.setOutputProperty(OutputKeys.INDENT, "yes") which is much better but now when I read the XML back in I have all these annoying text nodes that weren’t there before. All these text nodes contain a newline character “\n”. Is there any way to exclude them when I read the XML back in without having to write code to parse and remove them on my own? Some sort of filter maybe?

EDIT

I checked into Daniel’s suggestion to setIgnoringElementContentWhitespace(true) but came across two problems:

  1. I have to put the DOMBuilderFactory into validating mode
  2. Validating mode requires a DTD – I don’t have a DTD, the program I am creating allows the user to create new tags on the fly…

So to complicate things a bit more, is there a way to do this without a DTD? Or is there a simple way to create the DTD when I am saving the XML file?

  • 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-17T21:11:51+00:00Added an answer on May 17, 2026 at 9:11 pm

    AFAIK do most XML parsers have an option to skip empty text nodes, like they always occur. Xerces does, at least. The feature is called

    http://apache.org/xml/features/dom/include-ignorable-whitespace

    and allows to disable it (its enabled by default, if I read it right). Description:

    True:       Includes text nodes that can be considered "ignorable whitespace" in the DOM tree. 
    False:      Does not include ignorable whitespace in the DOM tree. 
    Default:    true 
    Note:       The only way that the parser can determine if text is ignorable
                is by reading the associated grammar and having a content model
                for the document. When ignorable whitespace text nodes are included
                in the DOM tree, they will be flagged as ignorable. The ignorable 
                flag can be queried by calling the
                TextImpl#isIgnorableWhitespace():boolean method.  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code written that converts my Document to a string prior to printing
I have an array of Car objects and using the following piece of code
I have a grails project that contains a few domain objects. I am using
I have a class that unmarshals xml from a 3rd party source (I have
I have an XSLT transform I am using to process an XML file, inserting
Is there a simple way to read from the global application.exe.config file from a
I am experiencing weird behaviour when trying to format xml output while modifying domdocument
I'm working with nHibernate. I have make an Assembly (ex : DAL.dll), which contains
Could someone please provide some good practice to handle exceptions in exception for example
I'm working with an XSL stylesheet, and I'm trying to use the method shown

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.