0
<?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.

Abbas
  • 14,186
  • 6
  • 41
  • 72
keerti_h
  • 383
  • 2
  • 13

2 Answers2

1

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();
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
0

You could use an XML Schema and use ID for the attribute type.

helb
  • 7,609
  • 8
  • 36
  • 58