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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:08:09+00:00 2026-06-11T04:08:09+00:00

I have a String which is XML data. After removing some nodes and adding

  • 0

I have a String which is XML data. After removing some nodes and adding few. The xml data is having lot of white spaces in it (created during the node removal.)

<A>
<B>
</B>

<!-- some node i deleted and lot of white spaces -->



<c>
</c>


<!-- some more node i deleted and lot of white spaces -->




<E>
</E>

Desired output after String manipulation

<A>
<B>
</B>
<c>
</c>
<E>
</E>
</A>

I can use replaceAll(“\s”,””) but this removes even the new line character and make the xml out of structure for displaying it in UI.

Is there a way to trim it without trimming the new line character?

Edit: This XML data is part of OMElement

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

    Can you clarify what you mean? If you mean whitespace other than new-lines, try as follows.

    str = str.replaceAll("[ \t\x0B\f\r]", "");
    

    … or, do you instead mean you want to remove extraneous new lines?

    str = str.replaceAll("\n{2,}", "\n");
    

    … or do you only want to remove only literal ' ' spaces?

    str = str.replace(" ", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel worksheet in XML format which contains <Cell ss:StyleID=s127><Data ss:Type=String>Replace Me</Data></Cell>
I have a service which i use to parse xml data (with sax) after
I have a string which has an xml inside. I want to write this
I have a PHP file which produces an Xml sitemap based on data which
I have some xml files, which are used in my application. They are stored
I have a XML document data.xml: I need to write python script which can
I have a .net web service that takes some xml data. From within the
I have an XML file which describes the data-structure that I can exchange on
Ok, here's my problem. I have a boost object which creates xml string via
I have a class A which reads an XML file and does some processing.

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.