[英]How can I get the attribute values for all the elements that's in an XML file using C#?
I am trying to pull the attribute values for each of the element that is in this XMl file ( XML below).我正在尝试提取此 XMl 文件(下面的 XML)中每个元素的属性值。 I want the attribute values for the following: type, label, CompTypes, readonly, hidden, and required.
我想要以下属性值:类型、label、CompTypes、只读、隐藏和必需。
Try:尝试:
var csv = string.Join(Environment.NewLine, XDocument.Load(@"D:\New Text Document.xml").Descendants()
.Where(element => element.Name.LocalName.Equals("element", StringComparison.CurrentCultureIgnoreCase))
.Select(x => new CustomElements()
{
Type = x.Attribute("type")?.Value,
Label = x.Attribute("label")?.Value,
CompTypes = x.Attribute("CompTypes")?.Value,
Readonly = x.Attribute("readonly")?.Value,
Hidden = x.Attribute("hidden")?.Value,
Require = x.Attribute("required")?.Value
}).Select(x => $"{x.Type}, {x.Label}, {x.CompTypes?.Replace(";", ",")}, readonly=\"{x.Readonly}\", hidden=\"{x.Hidden}\", required=\"{x.Require}\""));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.