Accessing XML elements with LINQ using VB.net (not C#)

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

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>

Answers


Try this:

Dim inputLocation As String = xdocument.Descendants("Configurations").Descendants("process").First(Function(c) c.Element("name").Value.Equals("MyProcess1")).Element("inputLocation").Value.Tri‌​m();

It basically just trims the \n character from the end of the value returned :). I've inserted Equals() instead of = just in case, but both should work :).


Need Your Help

Override JQuery previous callback function

javascript jquery callback

I am having this problem with a callback function. I have this function to display an alert message, and it has a callback (okcallback) to be executed if it is provided:

PHP - Issues with session variables

php ajax session-variables

I'm having an issue on my website. I'm not posting any code because I don't think there is anything relevant to show and I've done things alike several times. My question is just about logic.