XmlNodeList中

编程入门 行业动态 更新时间:2024-10-10 15:22:01
本文介绍了XmlNodeList中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我很亲近,而且我错过了一些愚蠢明显的东西......

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中

本文发布于:2023-11-11 08:20:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577867.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XmlNodeList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!