<?xml version="1.0" encoding="utf-8"?>
<projects>
<proj name="project1">
<file_type Type="internal">"path1"</file_type>
<file_type Type="external">"path2"</file_type>
</proj>
<proj name="project2">
<file_type Type="internal">"path3"</file_type>
</proj>
</projects>
This is my XML file. I need to add these file_type
values to my ComboBox list. For that, I need to check the uniqueness of the attribute values. Here I want to add only intenal and external inside the ComboBox. Please tell me any method to check uniqueness of attribute value.
You can get unique Type
values with Distinct()
:
var xdoc = XDocument.Load(path_to_xml); // use Linq to Xml
var types = xdoc.Descendants("file_type")
.Select(f => (string)f.Attribute("Type"))
.Distinct();
您可以使用XML模式,并使用ID作为属性类型。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.