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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:18:59+00:00 2026-06-02T15:18:59+00:00

I am getting XML with the following tags. What I do is, read the

  • 0

I am getting XML with the following tags. What I do is, read the XML file with Java using Sax parser and save them to database. but it seems that spaces are there after the p tag like below.

     <Inclusions><![CDATA[<p>                                               </p><ul> <li>Small group walking tour</li> <li>Entrance fees</li> <li>Professional guide </li> <li>Guaranteed to skip the long lines</li> <li>Headsets to hear the guide clearly</li> </ul>
                <p></p>]]></Inclusions>

But when we insert the read string to the database(PostgreSQL 8) it is printing bad charactors like below for those spaces.

\011\011\011\011\011\011\011\011\011\011\011\011

  • Small
    group walking tour
  • Entrance fees
  • Professional guide
  • Guaranteed to skip the long lines
  • Headsets to hear
    the guide clearly

\012\011\011\011\011\011

  1. I want to know why it is printing bad characters(011\011) like that ?

  2. What is the best way to remove spaces inside XML tags with java? (Or how to prevent those bad characters.)

I have checked samples and most of them with python samples.

This is how the XML reads with SAX in my program,

Method 1

  // ResultHandler is the class that used to read the XML. 
  ResultHandler handler         = new ResultHandler();
   // Use the default parser
  SAXParserFactory factory = SAXParserFactory.newInstance();
    // Retrieve the XML file
    FileInputStream in = new FileInputStream(new File(inputFile)); // input file is XML.
    // Parse the XML input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse( in , handler);

This is how the ResultHandler class used to read the XML as Sax parser with Method-1

import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

// other imports

    class ResultHandler extends DefaultHandler {

        public void startDocument ()
        {
            logger.debug("Start document");         
        }

        public void endDocument ()
        {
            logger.debug("End document");
        }

        public void startElement(String namespaceURI, String localName, String qName, Attributes attribs)
        throws SAXException {           
            strValue = "";      
            // add logic with start of tag. 
        }

        public void characters(char[] ch, int start, int length)
        throws SAXException {
            //logger.debug("characters");
            strValue += new String(ch, start, length);
            //logger.debug("strValue-->"+strValue);
        }

        public void endElement(String namespaceURI, String localName, String qName)
        throws SAXException {           
            // add logic to end of tag. 
        }
    }

So that need to know, how to set setIgnoringElementContentWhitespace(true) or similar with sax parser.

  • 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-02T15:19:01+00:00Added an answer on June 2, 2026 at 3:19 pm

    You can try to set for your DocumentBuilderFactory

    setIgnoringElementContentWhitespace(true)

    because of this:

    Due to reliance on the content model this setting requires the parser
    to be in validating mode

    you also need to set

    setValidating(true)

    Or the str= str.replaceAll("\\s+", ""); might as well work

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

Sidebar

Related Questions

Using the Venkman JavaScript debugger for Mozilla and getting the following error: XML Parsing
I have the following XML file getting populated via list view. I can't get
I have the following xml file that I need to read into my C#
I'm supposed to be getting XML output from the following php file that is
I'm getting the following XML-element back in an XML file. From this element I
I am getting an SPList values as xml using the following code. http://site1/_vti_bin/owssvr.dll?Cmd=Display&List= {listGuid}&Query=*&XMLDATA=TRUE
I'm having a hard time getting XML values from an XML file using XPath.
I have following XML configration i would like to convert to java property file.
I am reading an XML file using Stax parser and writing it using DOM
Can somebody please tell me what is wrong with the following pom.xml? i'm getting

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.