此代码使用属性获取 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;