I am trying to learn how to search XML trees with LINQ using VB.net. I've found some very helpful posts for C#, but none for VB.net
- How would I use LINQ to XML to get the value from example XML
- Getting a set of elements using linq
- How to get elements value with Linq To XML
I want to get the inputlocation for the process where name = "MyProcess1" Based on the example links above, I have been trying code like this:
Dim inputLocation As String = xdocument.Descendants("Configurations").Descendants("process").First(Function(c) c.Element("name").Value = "MyProcess1").Element("inputLocation").Value
But the code is not returning any values. here is the xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Configurations>
<process>
<name>MyProcess1</name>
<inputLocation> inputPath
</inputLocation>
<outputLocation> outputPath1
</outputLocation>
</process>
<process>
<name>MyProcess2</name>
<inputLocation> inputPath2
</inputLocation>
<outputLocation>outputPath2
</outputLocation>
</process>
</Configurations>