Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我使用LINQ连接到一个数据库,我得到一个属性列表,我想把它转换成一个XML文件_C#_Xml_Linq - Fatal编程技术网

C# 我使用LINQ连接到一个数据库,我得到一个属性列表,我想把它转换成一个XML文件

C# 我使用LINQ连接到一个数据库,我得到一个属性列表,我想把它转换成一个XML文件,c#,xml,linq,C#,Xml,Linq,下面是我使用linq登录数据库,然后使用C表达式收集所需数据的步骤。我想做的下一件事是将这些数据转换成XML,有什么想法吗 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Data; namespace VcacManagementTools.BuildProfiles { public static class BuildProfileT

下面是我使用linq登录数据库,然后使用C表达式收集所需数据的步骤。我想做的下一件事是将这些数据转换成XML,有什么想法吗

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Data;

namespace VcacManagementTools.BuildProfiles
{
    public static class BuildProfileTools
    {
        public static ICollection<string> GetExistingBuildProfileNames(string repositoryHostname,
                                                                       string repositoryUsername,
                                                                       string repositoryPassword)
        {

            var url = string.Format("https://{0}/repository/data/ManagementModelEntiti.svc", repositoryHostname);

            var managementModelClient = new DynamicOps.ManagementModel.ManagementModelEntities(new Uri(url))
                {
                    Credentials = new NetworkCredential(repositoryUsername, repositoryPassword)
                };



            return managementModelClient
                .GlobalProfiles
                .Select(gp => gp.ProfileName)
                .ToList();

我收到的输出是一个值列表

如果我理解得很好,您希望获取数据列表包含数据库中的数据并将其放入XML文件中。我使用变量来显示每个数据的存放位置

如果您有一个XML:

try
{
    doc = XDocument.Load(spath, LoadOptions.SetBaseUri);
    foreach(String propertyData in dataList)
    {
        XElement root = new XElement(ElementName);
        root.Add(new XElement("property1", propertyData));
        doc.Element(MainElement).Add(root);
    }
    doc.Save(spath);
}
catch (Exception)
{

}

如果您熟悉LINQ,为什么不试试LINQ到XML,那里有很多很棒的工具,语法与其他LINQ功能类似。您是否使用在代码中声明的DataTable?@YuriyGalanter抱歉,这是一个错误mistake@Evanlewis对不起,我是C新手,对LINQ还不太熟悉。你知道一个有教程的网站吗?这里有很好的教程,关于你的需要,请参考第2节或问题9。