问题描述
我知道我很亲近,而且我错过了一些愚蠢明显的东西......
I know I'm close, and I'm missing something stupidly obvious.....
我正试图让我的程序读取里面的每个项目我的XML文档的一部分。以下是一个示例:
I'm trying to get my program to read each item inside a section of my XML document. Here is an example:
<SQLScript>
<Build73>
<SQL FileName="Build_74.sql"/>
<SQL FileName="Build_80.sql" />
<SQL FileName="Build_75.sql" />
</Build73>
</SQLScript>
我正在尝试(现在)让程序显示每个SQL文件名item(Build_x.sql)。这是我最近的尝试:
I'm trying to (for now) get the program to display the SQL FileNames for each item (Build_x.sql). This has been my latest attempt:
public static void Upgrade(string db_Build, string sw_Build)
{
//find and open the the correct xml file
XmlDocument upgradeDoc = new XmlDocument();
upgradeDoc.Load(@"C:\Users\Tim\Desktop\C# Projects\Upgrade\DB_Upgrade\DB_Upgrade\bin\XML Docs\Build87.xml");
//var SQLScript = upgradeDoc.SelectSingleNode($"/SQLScript/section[@name='{db_Build}']");
XmlNodeList nodes = upgradeDoc.SelectNodes($"//SQLScript/{db_Build}");
foreach(XmlNode i in nodes)
{
Console.WriteLine(i.Value.ToString());
}
}
我非常强烈地认为问题在于我的XMLNodeList创建行,特别是在文件路径。任何人都可以就哪些内容错误提供一些建议,或者我可以在哪里阅读(有更好的例子)?
$
I feel pretty strongly that the issue lies in my XMLNodeList creation line, specifically in the file path. Can anybody offer me some advice on what piece is wrong, or where I can read up on this (with better examples)?
推荐答案
public static void Upgrade(string db_Build, string sw_Build)
{
//find and open the the correct xml file
XmlDocument upgradeDoc = new XmlDocument();
upgradeDoc.Load(@"C:\Users\Tim\Desktop\C# Projects\Upgrade\DB_Upgrade\DB_Upgrade\bin\XML Docs\Build87.xml");
//var SQLScript = upgradeDoc.SelectSingleNode(
这篇关于XmlNodeList中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!