0

I am parsing an XML doc into a c# project to check if an Element named "Feature" exists. In c#, I am using what exist in the Feature Element to determine whether an if statement should run.

XML

<Projects>
 <Project>
   <Name>Test</Name>
    <Feature>AutoDev;AutoRev</Feature>
 </Project>
</Projects>

C#

var feature = (from project in XDocument.Load(xmlPath).Descendants("Project")                                     
where project.Element("Name").Equals(Project)                                     
select project.Element("Feature").Value).Single().Split(';');

if (names.Contains("Test"))
      //then load ticket variables....
   if (feature.Contains("AutoDev"))
      //then do this....

Right now I receive an error: Sequence contains no elements

Using the any method was suggested when loading Feature to check if the element exist in the array. Not sure how to implement this though.

blkhdy
  • 33
  • 6

2 Answers2

3
project.Element("Name").Equals(ev.PortfolioProject)

should be

project.Element("Name").Value.Equals(ev.PortfolioProject)
                        ^
Anirudha
  • 32,393
  • 7
  • 68
  • 89
1

I think you are missing the .Value in project.Element("Name")

Try this:

var feature = (from project in XDocument.Load(xmlPath).Descendants("Project")                                     
where project.Element("Name").Value.Equals(ev.PortfolioProject)                                     
select project.Element("Feature").Value).Single().Split(';');
Esteban Elverdin
  • 3,552
  • 1
  • 17
  • 21