'xmlns:xsi' is a duplicate attribute name
<p>I am trying to write a xml editor where a specific xml file could be loaded , edited and then later-on saved for further usage. so structure of xml file must not changed.</p>

<p>I am trying to follow this <a href="https://stackoverflow.com/a/27809025/5861508">Stackoverflow question</a> , but Save XML command is giving exception while writing back to the file.  I am getting this error</p>

<p><a href="https://i.stack.imgur.com/fPegP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fPegP.png" alt="enter image description here"></a></p>

<p>which says i am having a duplicate attribute name, while i am loading from the file and changed nothing to that file.</p>

<p><strong>XML File Structure:</strong></p>

<pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;interlocking xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;signals&gt;
    &lt;signal ref="SignalRef_1"&gt;
      &lt;aspectSpeedDependencies&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
      &lt;/aspectSpeedDependencies&gt;
    &lt;/signal&gt;
    &lt;signal ref="SignalRef_1"&gt;
      &lt;aspectSpeedDependencies&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
        &lt;aspectSpeedDependency aspect="REF" vApproach="VApproach" vPass="Vpas"&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
          &lt;targetRef ref="TargetRef" /&gt;
        &lt;/aspectSpeedDependency&gt;
      &lt;/aspectSpeedDependencies&gt;
    &lt;/signal&gt;
  &lt;/signals&gt;
  &lt;routes&gt;
    &lt;route id="1"&gt;
      &lt;start&gt;
        &lt;signalRef ref="pro.Routes.Route.Start.SignalRef.Ref" /&gt;
      &lt;/start&gt;
      &lt;target&gt;
        &lt;signalRef ref="Target.SingalRef" /&gt;
      &lt;/target&gt;
      &lt;elements&gt;
        &lt;switchRef&gt;
          &lt;switch ref="Ref" course="Left" /&gt;
        &lt;/switchRef&gt;
        &lt;levelcrossingRef&gt;
          &lt;levelcrossing ref="Ref" beam="Beam" /&gt;
          &lt;levelcrossing ref="Ref" beam="Beam" /&gt;
          &lt;levelcrossing ref="Ref" beam="Beam" /&gt;
        &lt;/levelcrossingRef&gt;
        &lt;trainDetectorRef&gt;
          &lt;trackCircuitBorder ref="Ref" /&gt;
          &lt;trackCircuitBorder ref="Ref" /&gt;
          &lt;trackCircuitBorder ref="Ref" /&gt;
        &lt;/trainDetectorRef&gt;
      &lt;/elements&gt;
      &lt;flankElements&gt;Flank&lt;/flankElements&gt;
      &lt;routePriority rank="1" /&gt;
    &lt;/route&gt;
  &lt;/routes&gt;
&lt;/interlocking&gt;
</code></pre>

<p><strong>Code Behind</strong> </p>

<pre><code>      using System;
        using System.Collections.Generic;
        using System.Diagnostics;
        using System.IO;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Controls;
        using System.Windows.Data;
        using System.Windows.Documents;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Windows.Media.Imaging;
        using System.Windows.Shapes;
        using System.Xml;
        using System.Xml.Serialization;
        //using CoreElements.Core.Interlocking;
        using System.Xml.Linq;
        using System.Reflection;

        namespace TreeviewTest.Stck
        {
            /// &lt;summary&gt;
            /// Interaction logic for Window1.xaml
            /// &lt;/summary&gt;
            public partial class Window1 : Window
            {
                public Window1()
                {
                    InitializeComponent();
                }


                private void ExecutedLoadXML(object sender, ExecutedRoutedEventArgs e)
                {

                    string executableLocation = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    string xslLocation = System.IO.Path.Combine(executableLocation, "Interlocking.xml");

                    XDocument xmlData = XDocument.Load(xslLocation, LoadOptions.None);
                    var Interlocking = XmlSerializationHelper.LoadFromXML&lt;Interlocking&gt;(xmlData.ToString());

                    var children = new List&lt;Interlocking&gt;();
                    children.Add(Interlocking);

                    treeView1.ItemsSource = null;
                    treeView1.Items.Clear();
                    treeView1.ItemsSource = children;
                }

                private void ExecutedSaveXML(object sender, ExecutedRoutedEventArgs e)
                {
                    var planList = treeView1.ItemsSource as IList&lt;Interlocking&gt;;
                    if (planList != null &amp;&amp; planList.Count &gt; 0)
                    {
                        // Kludge to force pending edits to update
                        treeView1.Focus();
                        // Replace with actual save code!
                        Debug.WriteLine(planList[0].GetXml());
                    }
                }
            }

            public static class CustomCommands
            {
                public static readonly RoutedUICommand LoadXMLCommand = new RoutedUICommand("Load XML", "LoadXML", typeof(Window1));

                public static readonly RoutedUICommand SaveXMLCommand = new RoutedUICommand("Save XML", "SaveXML", typeof(Window1));
            }

            public static class XmlSerializationHelper
            {
                public static string GetXml&lt;T&gt;(T obj, XmlSerializer serializer, bool omitStandardNamespaces)
                {
                    using (var textWriter = new StringWriter())
                    {
                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Indent = true;        // For cosmetic purposes.
                        settings.IndentChars = "    "; // For cosmetic purposes.
                        using (var xmlWriter = XmlWriter.Create(textWriter, settings))
                        {
                            if (omitStandardNamespaces)
                            {
                                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                                ns.Add("", ""); // Disable the xmlns:xsi and xmlns:xsd lines.
                                serializer.Serialize(xmlWriter, obj, ns);
                            }
                            else
                            {
                                serializer.Serialize(xmlWriter, obj);
                            }
                        }
                        return textWriter.ToString();
                    }
                }

                public static string GetXml&lt;T&gt;(this T obj, bool omitNamespace)
                {
                    XmlSerializer serializer = new XmlSerializer(obj.GetType());
                    return GetXml(obj, serializer, omitNamespace);
                }

                public static string GetXml&lt;T&gt;(this T obj)
                {
                    return GetXml(obj, false);
                }

                public static T LoadFromXML&lt;T&gt;(this string xmlString)
                {
                    return xmlString.LoadFromXML&lt;T&gt;(new XmlSerializer(typeof(T)));
                }

                public static T LoadFromXML&lt;T&gt;(this string xmlString, XmlSerializer serial)
                {
                    T returnValue = default(T);

                    using (StringReader reader = new StringReader(xmlString))
                    {
                        object result = serial.Deserialize(reader);
                        if (result is T)
                        {
                            returnValue = (T)result;
                        }
                    }
                    return returnValue;
                }

                public static T LoadFromFile&lt;T&gt;(string filename)
                {
                    XmlSerializer serial = new XmlSerializer(typeof(T));
                    try
                    {
                        using (var fs = new FileStream(filename, FileMode.Open))
                        {
                            object result = serial.Deserialize(fs);
                            if (result is T)
                            {
                                return (T)result;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        throw;
                    }
                    return default(T);
                }
            }
        }
</code></pre>

<p>XAML:</p>

<pre><code>        &lt;Window x:Class="Test_Thesis.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                xmlns:o="clr-namespace:Test_Thesis"
                mc:Ignorable="d"
              Title="Window1" Height="300" Width="600"&gt;
            &lt;Window.CommandBindings&gt;
                &lt;CommandBinding Command="o:CustomCommands.LoadXMLCommand"  Executed="ExecutedLoadXML"/&gt;
                &lt;CommandBinding Command="o:CustomCommands.SaveXMLCommand" Executed="ExecutedSaveXML"/&gt;
            &lt;/Window.CommandBindings&gt;
            &lt;Window.Resources&gt;
                &lt;HierarchicalDataTemplate  DataType="{x:Type o:Interlocking}" ItemsSource="{Binding Path=Signals}"&gt;
                    &lt;TextBlock Text="Interlocking"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt;
                &lt;HierarchicalDataTemplate  DataType="{x:Type o:Signals}" ItemsSource="{Binding Path=Signal}"&gt;
                    &lt;TextBlock Text="Signal"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt;

                &lt;!--&lt;HierarchicalDataTemplate  DataType="{x:Type o:Signal}" ItemsSource="{Binding Path=AspectSpeedDependencies}"&gt;
                    &lt;TextBlock Text="Signals"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt;
                &lt;HierarchicalDataTemplate  DataType="{x:Type o:AspectSpeedDependencies}" ItemsSource="{Binding Path=AspectSpeedDependency}"&gt;
                    &lt;TextBlock Text="AspectSpeedDependencies"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt;--&gt;

                &lt;HierarchicalDataTemplate  DataType="{x:Type o:Signal}" ItemsSource="{Binding Path=AspectSpeedDependencies}"&gt;
                    &lt;Grid Margin="3" MinWidth="300"&gt;
                        &lt;Grid.RowDefinitions&gt;
                            &lt;RowDefinition /&gt;
                        &lt;/Grid.RowDefinitions&gt;
                        &lt;Grid.ColumnDefinitions&gt;
                            &lt;ColumnDefinition /&gt;
                            &lt;ColumnDefinition /&gt;
                        &lt;/Grid.ColumnDefinitions&gt;
                        &lt;TextBlock Text="Ref" Grid.Column="0" Grid.Row="0"/&gt;
                        &lt;TextBox Text="{Binding Path=Ref, Mode=TwoWay}" Grid.Column="1" Grid.Row="0"/&gt;
                    &lt;/Grid&gt;
                &lt;/HierarchicalDataTemplate &gt;
                &lt;HierarchicalDataTemplate  DataType="{x:Type o:AspectSpeedDependencies}" ItemsSource="{Binding Path=AspectSpeedDependency}"&gt;
                    &lt;TextBlock Text="AspectSpeedDependencies"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt;

                &lt;HierarchicalDataTemplate  DataType="{x:Type o:AspectSpeedDependency}" ItemsSource="{Binding Path=TargetRef}"&gt;

                    &lt;Border BorderBrush="Gray" BorderThickness="1" MinWidth="300"&gt;
                        &lt;StackPanel Height="auto" Width="auto"&gt;
                            &lt;TextBlock Text="AspectSpeedDependency:" /&gt;

                                &lt;StackPanel Orientation="Horizontal"&gt;

                                    &lt;TextBlock Text="Aspect:" Margin="1"/&gt;
                                &lt;TextBox Text="{Binding Path=Aspect, Mode=TwoWay}" Margin="1"/&gt;
                                &lt;TextBlock Text="VApproach:" Margin="1"/&gt;
                                &lt;TextBox Text="{Binding Path=VApproach, Mode=TwoWay}" Margin="1"/&gt;
                                &lt;TextBlock Text="VPass:" Margin="1"/&gt;
                                &lt;TextBox Text="{Binding Path=VPass, Mode=TwoWay}" Margin="1"/&gt;
                            &lt;/StackPanel&gt;



                                &lt;!--&lt;TextBlock Text="Aspect:" Grid.Column="0" Grid.Row="2"/&gt;
                                &lt;TextBox Text="{Binding Path=Aspect, Mode=TwoWay}" Grid.Column="1" Grid.Row="2"/&gt;
                                &lt;TextBlock Text="VApproach:" Grid.Column="0" Grid.Row="3"/&gt;
                                &lt;TextBox Text="{Binding Path=VApproach, Mode=TwoWay}" Grid.Column="1" Grid.Row="3"/&gt;
                                &lt;TextBlock Text="VPass:" Grid.Column="0" Grid.Row="4"/&gt;
                                &lt;TextBox Text="{Binding Path=VPass, Mode=TwoWay}" Grid.Column="1" Grid.Row="4"/&gt;--&gt;



                        &lt;/StackPanel&gt;

                    &lt;/Border&gt;
                &lt;/HierarchicalDataTemplate &gt;

                &lt;DataTemplate  DataType="{x:Type o:TargetRef}"&gt;
                    &lt;Border BorderBrush="Brown" BorderThickness="1" MinWidth="300"&gt;
                        &lt;Grid Margin="3" &gt;
                            &lt;Grid.RowDefinitions&gt;
                                &lt;RowDefinition /&gt;
                                &lt;RowDefinition /&gt;
                                &lt;RowDefinition /&gt;
                                &lt;RowDefinition /&gt;
                            &lt;/Grid.RowDefinitions&gt;
                            &lt;Grid.ColumnDefinitions&gt;
                                &lt;ColumnDefinition /&gt;
                                &lt;ColumnDefinition /&gt;
                            &lt;/Grid.ColumnDefinitions&gt;
                            &lt;TextBlock Text="Ref:" Grid.Column="0" Grid.Row="0"/&gt;
                            &lt;TextBox Text="{Binding Path=Ref, Mode=TwoWay}" Grid.Column="1" Grid.Row="0"/&gt;



                        &lt;/Grid&gt;
                    &lt;/Border&gt;
                &lt;/DataTemplate &gt;
    &lt;!-- if we remove below element it will show first leg of xml structure--&gt;
                &lt;HierarchicalDataTemplate  DataType="{x:Type o:Interlocking}" ItemsSource="{Binding Path=Routes}"&gt;
                    &lt;TextBlock Text="Routes"&gt;
                    &lt;/TextBlock&gt;
                &lt;/HierarchicalDataTemplate &gt; 
       &lt;/Window.Resources&gt;
            &lt;DockPanel&gt;
                &lt;ToolBarTray DockPanel.Dock="Top"&gt;
                    &lt;ToolBar&gt;
                        &lt;Button Command="o:CustomCommands.LoadXMLCommand" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"/&gt;
                        &lt;Button Command="o:CustomCommands.SaveXMLCommand" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"/&gt;
                    &lt;/ToolBar&gt;
                &lt;/ToolBarTray&gt;
                &lt;Grid DockPanel.Dock="Bottom"&gt;
                    &lt;TreeView Margin="3" Name="treeView1"&gt;
                        &lt;TreeView.ItemContainerStyle&gt;
                            &lt;Style TargetType="{x:Type TreeViewItem}"&gt;
                                &lt;Setter Property="IsExpanded" Value="True" /&gt;
                            &lt;/Style&gt;
                        &lt;/TreeView.ItemContainerStyle&gt;
                    &lt;/TreeView&gt;
                &lt;/Grid&gt;
            &lt;/DockPanel&gt;
        &lt;/Window&gt;
</code></pre>

<p><strong>XML C# code</strong></p>

<pre><code>   using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml.Serialization;


    namespace TreeviewTest.Stck
    {



    [XmlRoot(ElementName = "targetRef")]
    public class TargetRef
    {
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
    }

    [XmlRoot(ElementName = "aspectSpeedDependency")]
    public class AspectSpeedDependency
    {
        [XmlElement(ElementName = "targetRef")]
        public List&lt;TargetRef&gt; TargetRef { get; set; }
        [XmlAttribute(AttributeName = "aspect")]
        public string Aspect { get; set; }
        [XmlAttribute(AttributeName = "vApproach")]
        public string VApproach { get; set; }
        [XmlAttribute(AttributeName = "vPass")]
        public string VPass { get; set; }
    }

    [XmlRoot(ElementName = "aspectSpeedDependencies")]
    public class AspectSpeedDependencies
    {
        [XmlElement(ElementName = "aspectSpeedDependency")]
        public List&lt;AspectSpeedDependency&gt; AspectSpeedDependency { get; set; }
    }

    [XmlRoot(ElementName = "signal")]
    public class Signal
    {
        [XmlElement(ElementName = "aspectSpeedDependencies")]
        public List&lt;AspectSpeedDependencies&gt; AspectSpeedDependencies { get; set; }
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
    }

    [XmlRoot(ElementName = "signals")]
    public class Signals
    {
        [XmlElement(ElementName = "signal")]
        public List&lt;Signal&gt; Signal { get; set; }
    }

    [XmlRoot(ElementName = "signalRef")]
    public class SignalRef
    {
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
    }

    [XmlRoot(ElementName = "start")]
    public class Start
    {
        [XmlElement(ElementName = "signalRef")]
        public List&lt;SignalRef&gt; SignalRef { get; set; }
    }

    [XmlRoot(ElementName = "target")]
    public class Target
    {
        [XmlElement(ElementName = "signalRef")]
        public List&lt;SignalRef&gt; SignalRef { get; set; }
    }

    [XmlRoot(ElementName = "switch")]
    public class Switch
    {
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
        [XmlAttribute(AttributeName = "course")]
        public string Course { get; set; }
    }

    [XmlRoot(ElementName = "switchRef")]
    public class SwitchRef
    {
        [XmlElement(ElementName = "switch")]
        public List&lt;Switch&gt; Switch { get; set; }
    }

    [XmlRoot(ElementName = "levelcrossing")]
    public class Levelcrossing
    {
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
        [XmlAttribute(AttributeName = "beam")]
        public string Beam { get; set; }
    }

    [XmlRoot(ElementName = "levelcrossingRef")]
    public class LevelcrossingRef
    {
        [XmlElement(ElementName = "levelcrossing")]
        public List&lt;Levelcrossing&gt; Levelcrossing { get; set; }
    }

    [XmlRoot(ElementName = "trackCircuitBorder")]
    public class TrackCircuitBorder
    {
        [XmlAttribute(AttributeName = "ref")]
        public string Ref { get; set; }
    }

    [XmlRoot(ElementName = "trainDetectorRef")]
    public class TrainDetectorRef
    {
        [XmlElement(ElementName = "trackCircuitBorder")]
        public List&lt;TrackCircuitBorder&gt; TrackCircuitBorder { get; set; }
    }

    [XmlRoot(ElementName = "elements")]
    public class Elements
    {
        [XmlElement(ElementName = "switchRef")]
        public List&lt;SwitchRef&gt; SwitchRef { get; set; }
        [XmlElement(ElementName = "levelcrossingRef")]
        public List&lt;LevelcrossingRef&gt; LevelcrossingRef { get; set; }
        [XmlElement(ElementName = "trainDetectorRef")]
        public List&lt;TrainDetectorRef&gt; TrainDetectorRef { get; set; }

        [XmlIgnore]
        public IList ElementChildren
        {
            get
            {
                return new CompositeCollection()
            {
                new CollectionContainer() { Collection = SwitchRef },
                new CollectionContainer() { Collection = LevelcrossingRef },
                new CollectionContainer() { Collection = TrainDetectorRef }
            };
            }
        }
    }

    [XmlRoot(ElementName = "routePriority")]
    public class RoutePriority
    {
        [XmlAttribute(AttributeName = "rank")]
        public string Rank { get; set; }
    }

    [XmlRoot(ElementName = "route")]
    public class Route
    {
        [XmlElement(ElementName = "start")]
        public List&lt;Start&gt; Start { get; set; }
        [XmlElement(ElementName = "target")]
        public List&lt;Target&gt; Target { get; set; }
        [XmlElement(ElementName = "elements")]
        public List&lt;Elements&gt; Elements { get; set; }
        [XmlElement(ElementName = "flankElements")]
        public string FlankElements { get; set; }
        [XmlElement(ElementName = "routePriority")]
        public List&lt;RoutePriority&gt; RoutePriority { get; set; }
        [XmlAttribute(AttributeName = "id")]
        public string Id { get; set; }

        [XmlIgnore]
        public IList RouteChildern
        {
            get
            {
                return new CompositeCollection()
            {
                new CollectionContainer() { Collection = Start },
                new CollectionContainer() { Collection = Target },
                new CollectionContainer() { Collection = Elements },

                new CollectionContainer() { Collection = RoutePriority }

            };
            }
        }
    }


    [XmlRoot(ElementName = "routes")]
    public class Routes
    {
        [XmlElement(ElementName = "route")]
        public List&lt;Route&gt; Route { get; set; }
    }

    [XmlRoot(ElementName = "interlocking")]
    public class Interlocking
    {
        [XmlElement(ElementName = "signals")]
        public List&lt;Signals&gt; Signals { get; set; }
        [XmlElement(ElementName = "routes")]
        public List&lt;Routes&gt; Routes { get; set; }
        [XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
        public string Xsi { get; set; }
        [XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")]
        public string Xsd { get; set; }

        [XmlIgnore]
        public IList InterlockingChildren
        {
            get
            {
                return new CompositeCollection()
            {
                new CollectionContainer() { Collection = Signals },
                new CollectionContainer() { Collection = Routes }
            };
            }
        }
    }
}
</code></pre>

<p><strong>///UPDATE///</strong></p>

<pre><code>    private void ExecutedSaveXML(object sender, ExecutedRoutedEventArgs e)
    {
        var planList = treeView1.ItemsSource as IList&lt;Interlocking&gt;;
        if (planList != null &amp;&amp; planList.Count &gt; 0)
        {

            treeView1.Focus();

            // Replace Debug.WriteLine(planList[0].GetXml()); with following

            Debug.WriteLine(planList[0].GetXml(true));

        }
    }
}
</code></pre>

<p>if we send a "true" in this function, namespace issue is taken cared already in helper class. But @J.H solution is much better to use. Less string manipulation is always good.</p>