我知道我很亲近,而且我错过了一些愚蠢明显的东西......
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)?
推荐答案
您应该将SelectNodes XMLPath更改为 upgradeDoc.SelectNodes(
You should change the SelectNodes XMLPath toupgradeDoc.SelectNodes(
" // SQLScript / {db_Build} / SQL / @ FileName") ;看到beow "//SQLScript/{db_Build}/SQL/@FileName"); see beow
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/section[@name='{db_Build}']"); XmlNodeList nodes = upgradeDoc.SelectNodes(
更多推荐
XmlNodeList中
发布评论