Need for NewDataSet when processing data from web service

F

fergallydon

I'm retrieving some data from a webservice as follows

Dim RestXML As New Data.DataSet
Dim returnedXML As System.Xml.XmlDataDocument

RestXML.ReadXml(functionURL)
returnedXML = New XmlDataDocument(RestXML)

The return is something like this..

<?xml version="1.0" encoding="utf-8" ?>
- <CallResults>
- <ServiceOutput>
<accountBalance>46.5</accountBalance>
<rentalPrice>3.5</rentalPrice>
<purchasePrice>6.5</purchasePrice>
</ServiceOutput>
- <ServiceResult>
<ResultCode>01</ResultCode>
<ResultAdvisory>message</ResultAdvisory>
</ServiceResult>
</CallResults>

I extract the Result code as follows

strReturncode = returnedXML.DocumentElement.SelectSingleNode("/
CallResults/ServiceResult/ResultCode").InnerText

However with different input parameters to functionURL the XML
returned can be as follows (ServiceOutput is empty)

<?xml version="1.0" encoding="utf-8" ?>
- <CallResults>
<ServiceOutput />
- <ServiceResult>
<ResultCode>00</ResultCode>
<ResultAdvisory>Message</ResultAdvisory>
</ServiceResult>
</CallResults>

In this case there is a failure unless I add "/NewDataSet" to identify
which element I want to extract as follows.

strReturncode = returnedXML.DocumentElement.SelectSingleNode("/
NewDataSet/CallResults/ServiceResult/ResultCode").InnerText

Am I retrieving the response from the web service correctly. How can I
process it so that it works whether ServiceOutput is empty or not.

Thanks for reading.
 
J

John Saunders [MVP]

I'm retrieving some data from a webservice as follows

Dim RestXML As New Data.DataSet
Dim returnedXML As System.Xml.XmlDataDocument

RestXML.ReadXml(functionURL)
returnedXML = New XmlDataDocument(RestXML)

The return is something like this..

<?xml version="1.0" encoding="utf-8" ?>
- <CallResults>
- <ServiceOutput>
<accountBalance>46.5</accountBalance>
<rentalPrice>3.5</rentalPrice>
<purchasePrice>6.5</purchasePrice>
</ServiceOutput>
- <ServiceResult>
<ResultCode>01</ResultCode>
<ResultAdvisory>message</ResultAdvisory>
</ServiceResult>
</CallResults>

I extract the Result code as follows

strReturncode = returnedXML.DocumentElement.SelectSingleNode("/
CallResults/ServiceResult/ResultCode").InnerText

However with different input parameters to functionURL the XML
returned can be as follows (ServiceOutput is empty)

<?xml version="1.0" encoding="utf-8" ?>
- <CallResults>
<ServiceOutput />
- <ServiceResult>
<ResultCode>00</ResultCode>
<ResultAdvisory>Message</ResultAdvisory>
</ServiceResult>
</CallResults>

In this case there is a failure unless I add "/NewDataSet" to identify
which element I want to extract as follows.

strReturncode = returnedXML.DocumentElement.SelectSingleNode("/
NewDataSet/CallResults/ServiceResult/ResultCode").InnerText

Am I retrieving the response from the web service correctly. How can I
process it so that it works whether ServiceOutput is empty or not.

It would seem that you would have the same problem regardless of where you
got this XML from. Try loading the problem XML directly into an XmlDocument
and see if the problem still occurs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top