繁体   English   中英

如何将单个值从字符串[]传递到XDocument.Load流?

[英]How can I pass individual values from a string[] to the XDocument.Load Stream?

我有以下代码:

namespace ReadXMLfromFile
{
class Program
{
    static void Main(string[] args)
    {
            string path = args[0];

            Console.WriteLine("Looking in Directory: " + path);
            Console.WriteLine("Files in Directory:");

            string[] files = Directory.GetFiles(path, "*.xml");
            foreach (string file in files)
            {
               Console.WriteLine(Path.GetFileName(file));
            }

            XDocument doc = XDocument.Load(???????);

            var spec = doc.XPathSelectElement("project/triggers/hudson.triggers.TimerTrigger/spec").Value;

            //Write to the console

            Console.Write(spec);
            ....

我正在编写一个程序,该程序在单个目录中查看多个XML文件并提取XML元素。

我希望能够使用字符串数组中的每个文件名值,并将它们传递给XDocument.Load(),以便可以在控制台中编写所有提取内容。

您已经完成了大部分工作。 您需要将字符串uri的字符串一一传递给XDocument.Load

foreach (string path in Directory.EnumerateFiles(path, "*.xml", SearchOptions.AllDirectories))
{
    XDocument doc = XDocument.Load(path);
    var spec = doc.XPathSelectElement("project/triggers/
                                       hudson.triggers.TimerTrigger/spec").Value;  

    // Do something with spec.
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM