Dennis Pichlmeier Dennis Pichlmeier - 10 months ago 54
C# Question

Create XML File like my Example

I would like to Create an XML File. But now my problem is to create the following XML attribute:

<MsrProgram OwnerTypeFullName="myData" Number="0">

My problem are how to create the following attributes:

Here is my XML Class:

public class MsrProgram
/// <summary>
/// Gets or sets the MsrRange2Width.
/// </summary>
/// <remarks>
/// Value stored in ....
/// </remarks>
[XmlElementAttribute(ElementName = "MsrRange2Width")]
public string MsrRange2Width { get; set; }



Answer Source

Using Xml Linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication16
    class Program
        static void Main(string[] args)
            XElement msrProgram = new XElement("MsrProgram", new object[] {
                new XAttribute("OwnerTypeFullName","myData"),
                new XAttribute("Number", 0),
                new XElement("MsrRange2Width",4)