I have a call to a SOAP/XML type web service that is successfully returning an XML response.
So far, I have managed to take the returned object, cast it to an XmlNode object.. and have found the actual data in there as expected. All good.
Now, though, I want to bind my data to a DataGridView in a Windows Form. I saw a nice example here C# DataGridView binding to subset of XML using an XDocument and LINQ to provide a DataSource for the grid that would seem to work really well for me.
The problem I have is that I don't know how to create an XDocument based on the object returned by my call to the web service. How can I do this ?
This is how I have captured the returned data from the webservice.. which works..
' call the webservice '
Dim rawResults As Object = lw.runQuery(parameter1,parameter2)
Dim testresult As XmlNode = DirectCast(rawResults, XmlNode)
Dim docXml As New XmlDocument
docXml.AppendChild(docXml.ImportNode(testresult, True)).
.etc
Here is the XML returned by the webservice.. (Each "runQueryResult" will become a row in the DataGridView)
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<runQueryResponse xmlns="http://xxx.ddd.com/">
<runQueryResult>
<runQueryResponse xmlns="">
<runQueryRecord>
<catalogid>513</catalogid>
<name>Vacuum tube </name>
<this_month>0</this_month>
<month_past1>1</month_past1>
<month_past2>0</month_past2>
<month_past3>0</month_past3>
<month_past4>0</month_past4>
<month_past5>0</month_past5>
<month_past6>0</month_past6>
</runQueryRecord>
<runQueryRecord>
<catalogid>5311</catalogid>
<name>Adapter expansion</name>
<this_month>0</this_month>
<month_past1>1</month_past1>
<month_past2>0</month_past2>
<month_past3>0</month_past3>
<month_past4>0</month_past4>
<month_past5>0</month_past5>
<month_past6>0</month_past6>
... etc.
You can create XDocument
directly from XmlNode
, so you don't have to create XmlDocument
instance:
Dim xDoc As XDocument = XDocument.Load(New XmlNodeReader(testresults))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With