0
我需要一些幫助使用LINQ到XML,我一直在閱讀在線文章,但仍然沒有運氣,任何人都可以請幫我嗎?閱讀深層次的XML標籤與C#
我只需要讀取一個XML文件,我遇到的問題是它有很多子級別,我一直無法訪問它們。
<Dias>
<Dia id="0">
<Restricciones>
<Restriccion tipo="Ambiental" horaInicio="6" horaFin="10">
<Placas>
<Placa>4</Placa>
</Placas>
</Restriccion>
</Restricciones>
</Dia>
</Dias>
我當前的代碼是:
var dia = (int)DateTime.Now.DayOfWeek;
var xElement = XElement.Load("Bogota.xml");
var d = (from dias in xElement.Descendants("Dia")
where dias.Attribute("id").Value == dia.ToString()
select dias).First();
var rest = (from r in d.Descendants("Restricciones")
select r);
但我試過幾個變化,但至今沒有運氣
有人能幫忙嗎?
你想出來怎麼辦?請編輯您的問題以表明這一點。 – Crisfole
你試圖訪問的元素值? – Shyju