簡體   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