3 回答

TA貢獻1808條經驗 獲得超4個贊
嘗試不帶//
,例如childNode.SelectSingleNode("birim")
。兩個正斜杠表示 XML 文檔的根,我的猜測是birim
每次總是找到從根開始的第一個節點。

TA貢獻1890條經驗 獲得超9個贊
使用 xml linq :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication52
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<urun> uruns = doc.Descendants("urun").Select(x => new urun() {
resimDosyasi = (string)x.Element("resimDosyasi"),
aciklama = (string)x.Element("aciklama"),
birim = (string)x.Element("birim"),
miktar = (int)x.Element("miktar"),
toplam = (string)x.Element("toplam")
}).ToList();
}
}
public class urun
{
public string resimDosyasi { get; set; }
public string aciklama { get; set; }
public string birim { get; set; }
public int miktar { get; set; }
public string toplam { get; set; }
}
}

TA貢獻1836條經驗 獲得超3個贊
// 表示選擇節點,無論它們在當前上下文中的任何位置。當前上下文默認為根。要將結果限制為當前子節點下的結果,請遵循以下模式(只需添加一個點):
var urun_resim = childNode.SelectSingleNode(".//resimDosyasi").InnerText;
- 3 回答
- 0 關注
- 550 瀏覽
添加回答
舉報