此代碼使用該屬性獲取xml標記的值,我需要反轉此操作並使用xml的標記名稱獲取屬性值。我需要獲取XML父標記屬性
XElement main = XElement.Load(fi.FullName);
//Linq query for searching Ports address by ID Attributes
IEnumerable<XElement> searched =
from ports in main.XPathSelectElements("Network/Ports")
where (string)ports.Attribute("id") == fi.Name.Substring(0,36)
select ports;
這是行不通的,但它應該是圍繞此過程的東西我想獲得標籤名稱匹配的屬性。
//Something more like this
IEnumerable<XElement> searchedat =
from netatt in main.FirstAttribute = "id"
where netatt.Name == "Network"
select netatt;
請發表您正在使用和完整的代碼工作的XML結構。什麼是主要的? –
主要是XELEMENT XML對象或者你可以說它的XML文件我想解析屬性值 – shawn
你期望從這個表達式得到什麼樣的集合** main.FirstAttribute =「id」**?這是你在實驗代碼中迭代的內容。你不是指** main.Elements()。哪裏(el => el.FirstAttribute.Name ==「id」)**? – Tormod