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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:34:52+00:00 2026-05-23T08:34:52+00:00

I am new to editing XML and I have a few questions to problems

  • 0

I am new to editing XML and I have a few questions to problems I’m running into.

First: how do I add new lines after each writer.WriteEndElement();. I found examples using writer.WriteWhitespace("\n"); but it doesn’t seem to make any new lines.

Second: I think this may not be doing anything because of the previous problem but i wanted to indent my code using this at the end: writer.Formatting = Formatting.Indented;, but it doesn’t seem to do anything (most likely because i have no new lines).

Third: Since I’m appending this to a previous file i stripped out the closing tag for my main parent so that i could add this new data. I was hoping i could just have a writer.WriteEndElement(); to close the final tag but since i dont create an opening tag when im writing it doesn’t seem to realize that there’s an open tag. Is there an good way to do this or should i just end in code to write </closingTagName> at the end of the file.

Any comments or suggestions are appreciated.

  • 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-23T08:34:52+00:00Added an answer on May 23, 2026 at 8:34 am

    Try this:

    using (var stringWriter = new StringWriter())
    using (var writer = new XmlTextWriter(stringWriter))
    {
        writer.WriteRaw("</closingTagName>");
    
        writer.Formatting = Formatting.Indented;
        writer.Indentation = 10;
        writer.WriteStartElement("Element1");
    
        writer.WriteStartElement("Element2");
        writer.WriteString("test");
        writer.WriteEndElement();
    
        writer.WriteEndElement();
    
        writer.WriteWhitespace(Environment.NewLine);
    
        writer.WriteStartElement("Element3");
        writer.WriteEndElement();
    
        var result = stringWriter.ToString();
    

    Result:

    </closingTagName>  -- Closing tag
    <Element1>
              <Element2>test</Element2>  -- Line with the ident 10.
    </Element1>
                  -- extra new line
    <Element3 />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created new db via phpMyAdmin and while editing db privilages clicked delete localhost
I am new to emacs and I would like to use emacs-rails for editing
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
I have created a new migration: class AddSignatureToUser < ActiveRecord::Migration def self.up add_column :users,
I am somewhat new to SSIS. I have to deliver a 'generic' SSIS package,
Introduction first, question at the end. Please read carefully! I have a master-detail relation
I can't save any writing update to my RDF/XML OWL file using Protege. Each
I have a WPF application that encapsulates the editing of a dozen or so
I have a working Action and JSP form that I'm using for creating new
I'm new with Android and I have a problem with SAXParser I have a

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.