Bonjour,
Je cherche à parcourir un retour XML SOAP, pour en extraire le résultat, mais après des heures de test je m'avoue vaincu![]()
je ne trouve pas la bonne méthodologie pour accéder aux différents nodes, auriez-vous des pistes ?
Merci,
Bonne journée
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns1:IdentificationResponse xmlns:ns1="urn:Blurbe"> <IdentificationResult> <?xml version="1.0" encoding="ISO-8859-1"?> <e> <r> <agence>0001</agence> <client blocage="N" groupement="3">0012</client> <nom_soc>CLIENT DIVERS</nom_soc> </r> </e> </IdentificationResult> </ns1:IdentificationResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
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 Private Function XmlDatasReader_Identification(pStr As String) As String Dim output As String = "" Try Dim xmlDoc As New XmlDocument() xmlDoc.LoadXml(pStr) Dim nsManager = New XmlNamespaceManager(xmlDoc.NameTable) nsManager.AddNamespace("ns1", "urn:Blurbe") nsManager.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema") nsManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance") nsManager.AddNamespace("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/") Dim nodes As XmlNodeList = xmlDoc.SelectNodes("//SOAP-ENV:Envelope/SOAP-ENV:Header/SOAP-ENV:Body/ns1:IdentificationResponse/IdentificationResult/e/r/", nsManager) Dim agence As String = "", client As String = "", nom_soc As String = "" ' /////////////////////////////// For Each node As XmlNode In nodes If (node.SelectSingleNode("ns1:agence", nsManager) IsNot Nothing) Then agence = node.SelectSingleNode("ns1:agence", nsManager).InnerText If (node.SelectSingleNode("ns1:client", nsManager) IsNot Nothing) Then client = node.SelectSingleNode("ns1:client", nsManager).InnerText If (node.SelectSingleNode("ns1:nom_soc", nsManager) IsNot Nothing) Then nom_soc = node.SelectSingleNode("ns1:nom_soc", nsManager).InnerText output &= "agence : " & agence & " / " & "client : " & client & " / " & "nom_soc : " & nom_soc output &= "<br/>" Next ' /////////////////////////////// ' If output = "" Then output = "OuterXml : " & xmlDoc.OuterXml Catch ex As Exception output = ex.ToString End Try Return output End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 System.Xml.XPath.XPathException: L'expression doit être évaluée pour donner une collection de noeuds. à MS.Internal.Xml.XPath.XPathParser.ParseNodeTest(AstNode qyInput, AxisType axisType, XPathNodeType nodeType) à MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseExpresion(AstNode qyInput) à MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion) à System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver) à System.Xml.XPath.XPathNavigator.Compile(String xpath) à System.Xml.XmlNode.SelectNodes(String xpath, XmlNamespaceManager nsmgr) à Page_Test.XmlDatasReader_Identification(String pStr) dans \Test.aspx.vb:ligne 16
Partager