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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:06:22+00:00 2026-06-14T11:06:22+00:00

I am writing a tool that takes in an XML file, edits it by

  • 0

I am writing a tool that takes in an XML file, edits it by adding in elements and then saves it.
The tricky bit is that the XML files need to be maintained human readable, and in this case that doesn’t mean perfect formatting.

The input XElement contains many parameters such as this:

<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector>     </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector>    </Parameter>
<Parameter key="lorem">
    <Parameter key="ipsum">
        <Parameter key="dolor">
            <Vector> <Value>3</Value> <Value>4</Value> </Vector>
        </Parameter>
    </Parameter>
</Parameter

I want all XElements with name “Vector” and “Value” to disable indenting, but all XElements with name “Parameter” to maintain indenting.

Since my code isn’t allowed to mess up any of the existing formatting, I am forced to use LoadOptions.PreserveWhitespace on the source document. This, however, forces all XElements that I add to the document to loose any formatting. Is there a way I can force a particular XElement to apply formatting, even though the whole document doesn’t do it?

  • 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-14T11:06:23+00:00Added an answer on June 14, 2026 at 11:06 am

    This looks like the answer you are after.

    The key to solving this problem is to write a recursive function that
    iterates through the XML tree, writing the various elements and
    attributes to specially created XmlWriter objects. There is an ‘outer’
    XmlWriter object that writes indented XML, and an ‘inner’ XmlWriter
    object that writes non-indented XML.

    The recursive function initially uses the ‘outer’ XmlWriter, writing
    indented XML, until it sees the TextBlock element. When it encounters
    the TextBlock element, it creates the ‘inner’ XmlWriter object,
    writing the child elements of the TextBlock element to it. It also
    writes white space to the ‘inner’ XmlWriter.

    When the ‘inner’ XmlWriter object is finished with writing the
    TextBlock element, the text that the writer wrote is written to the
    ‘outer’ XmlWriter using the WriteRaw method.

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

Sidebar

Related Questions

I am writing a code generation tool that will take in a XSD file
I'm writing a tool that takes a user-inputted address and converts it to a
I'm writing a tool that needs to read a binary file one byte at
We're writing a diagnostic tool that needs to run for many hours at a
I'm writing a tool in Perl that needs to scan for certain binary patterns
For kicks I'm writing a schema documentation tool that generates a description of the
I'm writing a GUI tool using PowerShell that is able to do most AD
I'm writing a small visualization tool in wpf, the idea is that average users
I am writing one tool and I need to gather some information about running
I am writing a tool to scrape Javadoc from pre-existing Java source files and

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.