How to convert XML data of web service into DataSet

S

shakthi

Hi all,....i am developing an pocket PC application which consumes
USZip Webservice and display the data.

USZip has a GetInfoByZip(String zipcode) method which retuns an XML
data......

For Example....

USZip u = new USZip();

System.Console.WriteLine(u.GetInfoByZip("49544"));

****OutPut************
<?xml version="1.0" encoding="utf-8" ?>
- <NewDataSet>
- <Table>
<CITY>Grand Rapids</CITY>
<STATE>MI</STATE>
<ZIP>49544</ZIP>
<AREA_CODE>616</AREA_CODE>
<TIME_ZONE>E</TIME_ZONE>
</Table>
</NewDataSet>
********************************
I want this data to be displayed into a dataset....i tried using
DataSet.ReadXml(u.GetInfoByZip("49544"))...but iam getting an error
saying cannot convert Xml.XMlNode data into String..may be because
ReadXml() don't hav such type of argument......can any tell me how to
convert this Xml data into DataSet..................thankyou
 
S

sloan

Also look at this code:


private EmpDataDSWithValidateMethod GetDataSet1()
{
EmpDataDSWithValidateMethod ds = new EmpDataDSWithValidateMethod();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version=\"1.0\"?><EmpDataDS>");
sb.Append("<Emp>");
sb.Append("<EmpID>123</EmpID>");
sb.Append("<LastName>Smith</LastName>");
sb.Append("<FirstName>John</FirstName>");
sb.Append("<SSN>222-22-2222</SSN>");
sb.Append("<DateOfBirth>" + DateTime.Now.ToLongDateString() +
"</DateOfBirth>");
sb.Append("</Emp>");


sb.Append("<Emp>");
sb.Append("<EmpID>456</EmpID>");
sb.Append("<LastName>Jones</LastName>");
sb.Append("<FirstName>Mary</FirstName>");
sb.Append("<SSN>333-33-3333</SSN>");
sb.Append("<DateOfBirth>01/01/1972</DateOfBirth>");
sb.Append("</Emp>");


sb.Append("</EmpDataDS>");



System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
writer.Write(sb.ToString());
writer.Flush();
ms.Position = 0;
ds.ReadXml(ms);
return ds;



}



My sb.Append to make up a dataset is BAD coding (this is just sample code
above for testing), BUT check out how you can ReadXml a stream object.
 
S

shakthi

Also look at this code:

private EmpDataDSWithValidateMethod GetDataSet1()
{
EmpDataDSWithValidateMethod ds = new EmpDataDSWithValidateMethod();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<?xml version=\"1.0\"?><EmpDataDS>");
sb.Append("<Emp>");
sb.Append("<EmpID>123</EmpID>");
sb.Append("<LastName>Smith</LastName>");
sb.Append("<FirstName>John</FirstName>");
sb.Append("<SSN>222-22-2222</SSN>");
sb.Append("<DateOfBirth>" + DateTime.Now.ToLongDateString() +
"</DateOfBirth>");
sb.Append("</Emp>");

sb.Append("<Emp>");
sb.Append("<EmpID>456</EmpID>");
sb.Append("<LastName>Jones</LastName>");
sb.Append("<FirstName>Mary</FirstName>");
sb.Append("<SSN>333-33-3333</SSN>");
sb.Append("<DateOfBirth>01/01/1972</DateOfBirth>");
sb.Append("</Emp>");

sb.Append("</EmpDataDS>");

System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.StreamWriter writer = new System.IO.StreamWriter(ms);
writer.Write(sb.ToString());
writer.Flush();
ms.Position = 0;
ds.ReadXml(ms);
return ds;

}

My sb.Append to make up a dataset is BAD coding (this is just sample code
above for testing), BUT check out how you can ReadXml a stream object.











- Show quoted text -

but the GetInfoByZip("xx") is a XMLNode data...so how can i take this
into string???
 

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

Top