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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:04:36+00:00 2026-05-28T00:04:36+00:00

i have one xml file. lets say sample.xml with random position of tabs and

  • 0

i have one xml file. lets say sample.xml with random position of tabs and spaces:

<T1>
     <S1 >  D1 </S1>
 <S1>D2   </  S1>
 < S2 >D3  </S2>
 <S3> D4</S3>
</T1 >

I want to change data and format to something like this

<T1>
 <S1>D5</S1>
 <S1>D6</S1>
 <S2>D7</S2>
 <S3>D8</S3>
</T1>

I tried in sed, but it is not working for multiple line case as here.
How i can achieve same.

  • 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-28T00:04:37+00:00Added an answer on May 28, 2026 at 12:04 am

    Remove all whitespace from the file and then format it using xmllint

    $ sed 's/[[:space:]]//g' test.xml | xmllint --format -
    <?xml version="1.0"?>
    <T1>
      <S1>D1</S1>
      <S1>D2</S1>
      <S2>D3</S2>
      <S3>D4</S3>
    </T1>
    

    Background

    As pointed out by @choroba, your input data it not a valid XML file:

    $ cat test.xml
    <T1>
         <S1 >  D1 </S1>
          <S1>D2   </  S1>
           < S2 >D3  </S2>
            <S3> D4</S3>
            </T1 >
    

    The xmllint command states why:

    $ xmllint test.xml
    test.xml:3: parser error : expected '>'
          <S1>D2   </  S1>
                       ^
    test.xml:3: parser error : Opening and ending tag mismatch: S1 line 3 and unparseable
          <S1>D2   </  S1>
                       ^
    test.xml:4: parser error : StartTag: invalid element name
           < S2 >D3  </S2>
            ^
    test.xml:4: parser error : Opening and ending tag mismatch: T1 line 1 and S2
           < S2 >D3  </S2>
                          ^
    test.xml:5: parser error : Extra content at the end of the document
            <S3> D4</S3>
            ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
Let's say I have two strings: one is XML data and the other is
Hi I have one xml file successfully parsed my before. now i am change
I have an XML file which has many section like the one below: <Operations>
i have an xml file sitemap.xml as shown below ..i need to add one
I have an XML file that I'm trying to parse with Linq-to-XML. One of
I have an xml file like this: <root> <item> <name>one</name> <status>good</status> </item> <item> <name>two</name>
I am new to MVC and facing one issue. I have a xml file
I want to find all nodes in a xml file that have a certain
Let's say I have an XML file that looks like this: <a id=x> <b>

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.