|
-
Jul 29th, 2008, 09:43 AM
#1
Thread Starter
Fanatic Member
web method returning an array of an array
Hi,
I have a web service that returns the xml bellow. When I use MyDataset.ReadXml to put the xml in a dataset. It creates the datatable with 3 standard columns:
Name, value and ArrayOfMyObjectResponse_Id
When I check the content of the dataset, The contents of the XML gets splitted vertically into the dataset. Instead of that, I want my reading method to create a datatable with the columns to reflect each object of type MyObjectResponse :
The 4 columns should be:
contractid, contractnumber, Type and StartDate as you can see in the XML bellow. I put 3 rows returned as an example (ie: 2 instances of MyResponseObject).
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<n1:MyOBJECTResponse xmlns:n1="http://comapny.ca/Myapplication/submit"
xsi:type="n1:MyOBJECTResponse">
<MyResponseObject xsi:type="n1:MyResponseObject">
<MyResponseNV>
<name>contractid</name>
<value>567894</value>
</MyResponseNV>
<MyResponseNV>
<name>contractnumber</name>
<value>EOEE7654</value>
</MyResponseNV>
<MyResponseNV>
<name>Type</name>
<value>E</value>
</MyResponseNV>
<MyResponseNV>
<name>StartDate</name>
<value>2008/01/12</value>
</MyResponseNV>
</MyResponseObject>
<MyResponseObject xsi:type="n1:MyResponseObject">
<MyResponseNV>
<name>Contractid</name>
<value>28618098</value>
</MyResponseNV>
<MyResponseNV>
<name>contractnumber</name>
<value>POED176000</value>
</MyResponseNV>
<MyResponseNV>
<name>Type</name>
<value>P</value>
</MyResponseNV>
<MyResponseNV>
<name>StartDate</name>
<value>2008/01/12</value>
</MyResponseNV>
</MyResponseObject>
<MyResponseObject xsi:type="n1:MyResponseObject">
<MyResponseNV>
<name>Contractid</name>
<value>28618098</value>
</MyResponseNV>
<MyResponseNV>
<name>contractnumber</name>
<value>45ERTFDSE</value>
</MyResponseNV>
<MyResponseNV>
<name>Type</name>
<value>P</value>
</MyResponseNV>
<MyResponseNV>
<name>StartDate</name>
<value>2008/01/12</value>
</MyResponseNV>
</MyResponseObject>
</n1:MyOBJECTResponse>
</env:Body>
</env:Envelope>
Thanks a lot for your help.
-
Jul 29th, 2008, 10:29 AM
#2
Re: web method returning an array of an array
You could create a function to convert the data:
Code:
Private Shared Function CovertMyResponse(ByVal originalData As DataTable) As DataTable
'setup new columns
Dim convertedTable As New DataTable(originalData.TableName & "_Converted")
With convertedTable.Columns
.Add("contractid", GetType(Int32))
.Add("contractnumber", GetType(String))
.Add("Type", GetType(Char))
.Add("StartDate", GetType(Date))
End With
'populate new columns with original data
Dim convertedRow As DataRow = Nothing
For Each originalRow As DataRow In originalData.Rows
Dim name As String = CStr(originalRow("name"))
Select Case name.ToLower
Case "contractid"
convertedRow = convertedTable.NewRow
convertedTable.Rows.Add(convertedRow)
convertedRow(name) = originalRow("value")
Case Else
convertedRow(name) = originalRow("value")
End Select
Next
Return convertedTable
End Function
If you've got control of the data, it maybe best for you to modify the way you retrieve it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|