LINQ to XML node path question

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have an XML file:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; MyConfig<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FileSynchTasks<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Customer <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Klient1<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; a<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; in<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /in/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /in<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; b<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; out<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /out/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /out<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; z<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /zz/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /zz<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; Customer<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Customer <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Klient2<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; aa<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; in<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /in/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /in<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; bb<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; out<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /out/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /out<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; FileSynchTask <span style="color:Red; Name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; " <span style="color:Red; Direction<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zz<span style="color:Black; " <span style="color:Red; FTPPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /zz/<span style="color:Black; " <span style="color:Red; LocalPath<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /zz<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; Customer<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; FileSynchTasks<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; MyConfig<span style="color:Blue; >
[/code]

<br/>
I read all FileSynchTask node using this code and it works perfect:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim root <span style="color:Blue; As XElement = XElement.Load(<span style="color:#A31515; "XMLFile1.xml")
<span style="color:Blue; Dim tasks <span style="color:Blue; As IEnumerable(Of XElement) = _
<span style="color:Blue; From el <span style="color:Blue; In root...<FileSynchTask> _
<span style="color:Blue; Select el
<span style="color:Blue; For <span style="color:Blue; Each task <span style="color:Blue; As XElement <span style="color:Blue; In tasks
Debug.Print(task.Parent.@Name & <span style="color:#A31515; " " & task.@Name & <span style="color:#A31515; " " & task.Value)
<span style="color:Blue; Next
[/code]

<br/>
but I would like refer to FileSynchTask nodes in a full path way to avoid taking into account any other FileSynchTask nodes which can occure in this file outside my intended structure. I have tried these two but no effect:
root.<MyConfig>.<FileSynchTasks>.<Customer>...<FileSynchTask>
root...<MyConfig>.<FileSynchTasks>.<Customer>.<FileSynchTask>

Please help here.

View the full article
 
Back
Top