如何从xml文档中获取数据并写入文本文件?

时间:2018-05-10 04:17:12

标签: c#

USE master
GO
SELECT 
   'ALTER LOGIN ' + QUOTENAME([name]) COLLATE SQL_Latin1_General_CP1_CI_AS + 
' WITH DEFAULT_DATABASE = ' + 
    spr.default_database_name COLLATE SQL_Latin1_General_CP1_CI_AS
   + 'GRANT ' + spe.permission_name  + ' to ' + QUOTENAME([name])
   + CASE WHEN spr.default_database_name IS NOT NULL
        THEN ' WITH DEFAULT DATABASE = ' + spr.default_database_name
        ELSE 
        ''
    END
FROM sys.server_principals spr INNER JOIN 
 sys.server_permissions spe  ON spr.principal_id = spe.grantee_principal_id
WHERE spr.type_desc IN ('WINDOWS_GROUP', 'WINDOWS_LOGIN')

1 个答案:

答案 0 :(得分:0)

有一种方法可以达到这个目的:

using System;
using System.IO;
using System.Xml;

public class SampleXML
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.Load("TaskName.xml");

    //Display the desired tag.
    XmlNodeList elemList = doc.GetElementsByTagName("name");
    for (int i=0; i < elemList.Count; i++)
    {   
      Console.WriteLine(elemList[i].InnerXml);
    }  

  }
}

or this?

or maybe this?

definitely look at this!