Using LINQ to select nested elements by attribute in XML

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<p style=" I am working with WSDL XML services at <a title="http://www2.mvr.usace.army.mil/OMNI/ws/OMNIdata.cfm?river=TN&rptname=vessel_current_location http://www2.mvr.usace.army.mil/OMNI/ws/OMNIdata.cfm?river=TN&rptname=vessel_current_location" target="_blank" style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#0066dd; text-decoration:none; list-style-type:none; padding:0px; margin:0px; border:0px none initial http://www2.mvr.usace.army.mil/OMNI/ws/OMNIdata.cfm?river=TN&rptname=vessel_current_location
<p style=" My code (at the bottom) works great for getting all of the information from the service. However, I would like to know which pool the vessel is in and be able to query by pool (load all the vessels in pool #2, etc.). I would also like to know how
to load this into a datagridview (rather than just write it to the console).
<p style=" Here is a simplified sample of the data
<p style="
<div style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; background-color:white; padding:0px; margin:0px; border:0px initial initial
<pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; text-align:left; padding:0px; margin:0px; border:0px none initial <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial pool <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial poolnum<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 1<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial name<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial vessel name1<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial " <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial number<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 12<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ><span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial name<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial vessel name2<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial " <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial number<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 34<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ><span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial pool<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial pool <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial poolnum<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 2<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial name<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial vessel name3<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial " <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial number<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 72<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ><span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial name<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial vessel name4<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial " <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial number<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 74<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ><span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial name<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial vessel name5<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial " <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:red; padding:0px; margin:0px; border:0px initial initial number<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial =<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial 84<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:black; padding:0px; margin:0px; border:0px initial initial "<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial ><span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial vessel<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >
<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial </<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:#a31515; padding:0px; margin:0px; border:0px initial initial pool<span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial >[/code]
<pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; text-align:left; padding:0px; margin:0px; border:0px none initial <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <br/>[/code]
<pre style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; list-style-type:none; text-decoration:none; word-wrap:break-word; text-align:left; padding:0px; margin:0px; border:0px none initial <span style="font-weight:inherit; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; color:blue; padding:0px; margin:0px; border:0px initial initial <div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim doc = XDocument.Load(<span style="color:#A31515; "http://www2.mvr.usace.army.mil/OMNI/ws/OMNIdata.cfm?river=TN&rptname=vessel_current_location")

<span style="color:Blue; Dim query = _
<span style="color:Blue; From c <span style="color:Blue; In doc.<SERVER>.<POOL>.<VESSEL> _
<span style="color:Blue; Where c.<SERVER>.<POOL_NUMBER>.Value = <span style="color:#A31515; "1" _
<span style="color:Blue; Select c

<span style="color:Blue; For <span style="color:Blue; Each result <span style="color:Blue; In query
Console.WriteLine(result)
<span style="color:Blue; Next

[/code]
<br/>[/code]



View the full article
 
Back
Top