XDocument 获取根属性值
本文关键字:属性 获取 XDocument | 更新日期: 2023-09-27 18:30:47
如何使用 xDocument 从数据表中的此字符串中获取 title1 的值
<Person ActionType = "Update" Title1="Miss" />
我尝试了后代,XA属性和各种...也许输入是错误的,但是
XDocument xml = XDocument.Parse(row["XMLTransaction"].ToString());
IEnumerable<XAttribute> query =
from transaction in xml.Root.Elements()
select transaction.Attribute(attribute);
如果该字符串是文字 XML,则应省略.Elements()
部分。
使用XElement而不是XDocument更短:
var xml = XElement.Parse(row["XMLTransaction"].ToString());
IEnumerable<XAttribute> query = xml.Attributes();