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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:51:48+00:00 2026-06-05T04:51:48+00:00

i have a string in single line String s = <Item><productname>COOLER MASTER Hyper 212

  • 0

i have a string in single line

String s = "<Item><productname>COOLER MASTER Hyper 212 EVO RR-212E-20PK-R2
</productname><Price>$33.99</Price><ItemID>1000</ItemID></Item>";

inside the above string , after the “>” new line should started and required output should like

<Item>
 <productname>COOLER MASTER Hyper 212 EVO RR-212E-20PK-R2 </productname>
 <Price>$33.99</Price> 
 <ItemID>1000</ItemID>
</Item>
  • 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-05T04:51:50+00:00Added an answer on June 5, 2026 at 4:51 am

    Another option is to parse the XML, and use the OutputKeys.INDENT option of the Transformer class to output the XML formatted.

    The following example

    Source source = new StreamSource(new StringReader(s));
    
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setAttribute("indent-number", 4);
    
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    
    StreamResult result = new StreamResult(new StringWriter());
    transformer.transform(source, result);
    
    String xmlOutput = result.getWriter().toString();
    System.out.println(xmlOutput);
    
    String xmlOutput = result.getWriter().toString();
    System.out.println(xmlOutput);
    

    produces the output below

    <?xml version="1.0" encoding="UTF-8"?>
    <Item>
        <productname>COOLER MASTER Hyper 212 EVO RR-212E-20PK-R2</productname>
        <Price>$33.99</Price>
        <ItemID>1000</ItemID>
    </Item>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single string that contains the command-line parameters to be passed to
I have to generate a single string containing all the data members of a
I have a string like this BRADI5G20430|BRADI5G20430.1||1 How can I replace the bar (single
I have an if statement, and I need to compare a single string with
I create a single mutable string object. Now I have released the object many
Possible Duplicate: Concatenate many rows into a single text string? I have a query
I have a single AMQ queue that receives simple messages with string body. Consider
I have a very large string that needs to escape all the single quotes
I have the following connection string, and you will notice Provider's.Tests, notice the single
Is there a decent way to declare a long single line string in C#,

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.