0

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

2 回答 2

0
var xDoc = XDocument.Parse("XML String");
var attributeValue = xDoc.Root.Element("Name of the element").Attribute("Name of attribute").Value

您可能需要根据您的 XML 结构进一步解析 xml 树

于 2013-07-28T04:11:23.177 回答
0
IEnumerable<XElement> searched =
from ports in main.XPathSelectElements("Network/Ports")
where ports.LocalName == "TagNameToCompareHere"
select ports.Attribute("id").Value;
于 2013-07-28T04:23:14.607 回答