Deal with White Spaces : XElement « XML LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

    public class MainClass
    {
        public static void Main()
        {
            XElement root = null;
            string path=Application.StartupPath + @"\employees.xml";
            root=XElement.Load(path, LoadOptions.None);
            MessageBox.Show(root.ToString());
            root.Save(path, SaveOptions.None);

            //root=XElement.Load(path, LoadOptions.PreserveWhitespace);
            //MessageBox.Show(root.ToString());
            //root.Save(path, SaveOptions.DisableFormatting);
        }
    }








31.2.XElement
31.2.1.Parse Load xml from hard coded string
31.2.2.XML Fragments
31.2.3.Get Descendants for a node
31.2.4.Deal with White Spaces
31.2.5.Load xml from string, text file
31.2.6.Remove an element