Hi All,
I have created a webservice that returns XML data to be processed by the client.
The returned XML contains a complex type that I created, as well as having a number of nested objects on which I have used the XMLARRAY / XMLARRAYITEM.
Fragment of test XML shown below...
<?xmlversion="1.0"encoding="utf-8"?><Testxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://tempuri.org">
<test1>201</test1><test2>Blah Blah</test2>
<test3>3</test3><test4>51</test4>
<TestTest><Inner>
<inner1>300</inner1><inner2>TEXT</inner2>
<inner3>TEXT</inner3><inner4>TEXT</inner4>
<inner5>TEXT</inner5><inner6>TEXT</inner6>
<inner7>TEXT</inner7><inner8>TEXT</inner8>
<inner9>TEXT</inner9><inner10>TEXT</inner10>
</Inner><Inner>
<inner1>301</inner1><inner2>TEXT</inner2>
<inner3>TEXT</inner3><inner4>TEXT</inner4>
<inner5>TEXT</inner5><inner6>TEXT</inner6>
<inner7>TEXT</inner7><inner8>TEXT</inner8>
<inner9>TEXT</inner9><inner10>TEXT</inner10>
</Inner> </TestTest></Test>
Now when I use the test harness the XML is generated exactly as I require.
Also I can reference the returned data on the client, for example by using arg.test1 would return '201'.
My probelms/question are these...
1> How do I access the inner array items. For example how would I access elements under TestTest?
2> How do I convert the returned data from the webservice into valid xml on the client? Every time I try and do this I get the error 'XML document must have a top level element'.
I cant understand why it says it is not valid as every other application I have has no problem with the XML that is generated,
Can anyone point me in the right direction as I cant see where the problem is.
Thanks in advance
Problem sorted
Once I found out about the service using JSON by default it was very straightforward.
I looked at the JSON formatted data that was sent with the response. From there it was obvious how to call the array items.
For example arg.Level1[1].Level2Value
Didn't know much about JSON before this but it is a great format (compared to XML) to use when you want to handle stuff on the client in javascript. Even handles custom objects with ease.
Hope this helps somebody
No comments:
Post a Comment