Use VB XML literals:
Dim marker2 = From x In data...<Procedure-Text> _
Where x.<A>.@ID = "marker2" _
Select x
The triple dot syntax produce "all descendants" of an xml element, i.e. data...<Procedure-Test>
will produce a list of <Procedure-Test>
tags inside data
The dot syntax on XML literals means "first descendant" so x.<A>
will produce the first occurence of <A>
inside x. Of which x is now instance of <Procedure-Test>
And now that you have the desired <A>
element, comparing its id to a string is trivial with the @attr
attribute selector. <A>.@ID = "marker2"
will evaluate to True
if the ID attribute of the <A>
tag is equal to "marker2"
So x.<A>.@ID
means "The ID attribute of the first <A>
tag inside x"
And you want the <Procedure-Text>
element, so you specify Select x
Full example:
Sub Main()
Dim data = <doc>
<Procedure-Text>
<A ID="marker1"></A>Do This Procedure
</Procedure-Text>
<Procedure-Text>
<A ID="marker2"></A>Do That Procedure
</Procedure-Text>
</doc>
Dim marker2 = From x In data...<Procedure-Text> _
Where x.<A>.@ID = "marker2" _
Select x
' prints the second procedure-text element
Console.WriteLine(marker2.FirstOrDefault().ToString())
Console.ReadKey()
End Sub