xmlstringcsvconcatenationxattribute

XML Concatenate an string to set as an XAttribute


I am reading in a CSV file to convert to XML format. How do I concatenate a fixed string before one of the fields.

In this example i need to attach "domain\" to the username

string[] csvString = File.ReadAllLines("file.csv");

        XElement xmlString = 
            new XElement("XML",
                new XElement("IDENTITIES",
                from str in csvString
                let fields = str.Split(',')
                select  new XElement("IDENTITY", 
                            new XAttribute("ID", fields[1]),
                            new XAttribute("SERVICE", "SERV"),
                            new XAttribute("DOMAIN_USER",  fields[2]),
                            new XAttribute("PASSWORD","PASSWORD")

How would I set DOMAIN_USER XAttribute to a concatenated "DOMAIN\" & fields[2]?


Solution

  • Why don't you simply concatenate strings ?

    new XAttribute("DOMAIN_USER",  "DOMAIN\\" + fields[2]),