.NET Tips and Tricks

Blog archive

Control XML Output with SaveOptions

As my column Creating Complex XML Documents with XML Literals indicates, I think your best choice for creating complex XML documents is to use XML Literals with the XElement object. As I note in that column, generating the XML document from an XElement object is easy: Just call the Save method, passing a file name. That gives you a beautiful XML document, with each nested element nicely indented and starting on a new line.

But, of course, if you're just going to pass that document to some other process then all that "pretty printing" is a waste of time. You're better off passing SaveOptions.DisableFormatting as the second parameter to the Save method which saves your XML without indentation:

Dim elm As XElement
elm.Save("c:\test.xml", SaveOptions.DisableFormatting)

There, that's much simpler.

Posted by Peter Vogel on 01/16/2015


comments powered by Disqus

Featured

  • Linear Regression Using JavaScript

    Dr. James McCaffrey presents a complete end-to-end demonstration of linear regression using JavaScript. Linear regression is the simplest machine learning technique to predict a single numeric value, and a good way to establish baseline results for comparison with other more sophisticated regression techniques.

  • Creating Simple Chat Bots with Microsoft Fabric Datastores

    At Visual Studio Live! San Diego, Ginger Grant of Desert Isle Group will lead a practical, demo-driven session on how to build simple yet powerful chatbots using Microsoft Fabric lakehouses and warehouses. Attendees will learn how to use AI skills and grounding techniques to enable conversational data access -- quickly and cost-effectively. Ideal for developers ready to extend analytics with conversational interfaces.

  • Prompt Engineering? See VS Code Team's System Prompts for Copilot Chat, Now Open Source

    "Explore the codebase and learn how agent mode is implemented, what context is sent to LLMs, and how we engineer our prompts."

  • VS Code Goes Transparent as Open-Source AI Editor

    Microsoft has open sourced the GitHub Copilot Chat extension, marking a major step in turning VS Code into an open-source AI editor focused on transparency, collaboration, and community-driven development.

  • New Default Model for Visual Studio Copilot, So How Do You Choose?

    Along with a new default model, a new Consumptions panel in the IDE helps developers monitor their usage of the various models, paired with UI to help easily switch among models.

Subscribe on YouTube