Parsing avec Xpath/Linq NameSpace
Bonsoir à tous,
je colle sur un problème depuis 2 jours et je dois dire que j'ai un peu tout essayé... sans resultat. Je pense que mon problème vient du NameSpace, mais en ayant tout essayé avec le namespace, pas mieux.
Je souhaite parser une reponse sur une requete REST, la requete fonctionne et j'ai mis le resultat dans le code ci-dessous :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
Public Sub LinqTrioShowsGet()
'Dim mdocument As XDocument = XDocument.Load("http://" + MonIP.Text + ":8580/directory/shows/")
Dim mdocument As XDocument = <?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="http://localhost:8580/directory/shows/">
<id>tag:kenjy,2013-07-01:0:/directory/shows/</id>
<title>Directory feed for http://localhost:8580/directory/shows/</title>
<updated>2013-07-01T20:40:05Z</updated>
<link href="http://localhost:8580/directory/shows/" rel="self" type="application/atom+xml;type=feed"/>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:viz="http://www.vizrt.com/atom">
<title>ShowTest_A</title>
<author>
<name>Media Sequencer Engine</name>
</author>
<id>tag:kenjy,2013-07-01:0:/directory/shows/ShowTest_A.show</id>
<updated>2013-07-01T20:40:05Z</updated>
<summary>Show ShowTest_A</summary>
<category term="directory" scheme="http://www.vizrt.com/types"/>
<category term="show" scheme="http://www.vizrt.com/types"/>
<category term="trio_legacy_collection" scheme="http://www.vizrt.com/types" label="Trio Legacy Collection"/>
<link href="http://localhost:8580/show/directory/shows/ShowTest_A.show/" rel="alternate" type="application/atom+xml;type=feed"/>
<link href="http://localhost:8580/directory/shows/ShowTest_A.show" rel="self" type="application/atom+xml;type=entry"/>
<viz:empty>false</viz:empty>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:viz="http://www.vizrt.com/atom">
<title>ShowTest_B</title>
<author>
<name>Media Sequencer Engine</name>
</author>
<id>tag:kenjy,2013-07-01:0:/directory/shows/ShowTest_B.show</id>
<updated>2013-07-01T20:40:05Z</updated>
<summary>Show ShowTest_B</summary>
<category term="directory" scheme="http://www.vizrt.com/types"/>
<category term="show" scheme="http://www.vizrt.com/types"/>
<category term="trio_legacy_collection" scheme="http://www.vizrt.com/types" label="Trio Legacy Collection"/>
<link href="http://localhost:8580/show/directory/shows/ShowTest_B.show/" rel="alternate" type="application/atom+xml;type=feed"/>
<link href="http://localhost:8580/directory/shows/ShowTest_B.show" rel="self" type="application/atom+xml;type=entry"/>
<viz:empty>false</viz:empty>
</entry>
</feed>
Dim ns As XNamespace = "http://www.vizrt.com/atom"
Dim response As IEnumerable(Of XElement) = From c In mdocument.Elements(ns + "entry") _
Where c.Element("link")
For Each e In response
rtBox1.Text += Chr(13) & e.ToString() & Chr(13)
Next
End Sub |
je n'ai pas d'erreur à l'execution, mais je n'ai pas de resultat non plus :(
Je pense que mon code est "bon", mais pas de resultat à la requete LINQ ????
J'ai tester autrement et j'ai des résultats, mais pas ceux attendu par l'expression XPATH... là je ne sais plus.
J'ai aussi essayé ça et pas mieux :
Code:
1 2 3 4 5 6 7 8 9 10 11
| Public Sub ShowXML()
Dim doc As New XmlDocument
doc.LoadXml(WebRequestGet("http://" + MonIP.Text + ":8580/profiles"))
Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom")
nsmgr.AddNamespace("viz", "http://www.vizrt.com/atom")
For Each Entry As XmlNode In doc.SelectNodes("/viz:entry")
rtBox1.Text += Entry.SelectSingleNode("viz:title").InnerText & Chr(13) & "--------" & Chr(13)
Next
End Sub |
Comme vous vous en doutez, je souhaite récupérer les balises "link/@href" dans chaque pack "entry"... et s'il y a une différence entre les "link" namespace ou autres, merci de me dire pourquoi...
Merci de m'aiguiller vers une solution du type LINQ ou Xpath.
Patrick