How to convert Xml data from Webservice to Data Table

219 views
Skip to first unread message

shakthi

unread,
Jul 5, 2007, 5:05:39 PM7/5/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
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>


this the output which i get if i print it out in console...but i want
this data to be converted in to datatable..and displyed using
GridView......

Aman Sharma

unread,
Jul 6, 2007, 12:52:45 AM7/6/07
to DotNetDe...@googlegroups.com
Hi,
 
Take this data into DataSet and then bind data View using this dataset.

 

Cerebrus

unread,
Jul 6, 2007, 2:18:11 AM7/6/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Look at the Dataset.ReadXml(string) method. HTH.

shakthi

unread,
Jul 6, 2007, 1:17:57 AM7/6/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi, thanks for the reply....
how can i take this data to dataset???

On Jul 6, 12:52 am, "Aman Sharma" <kajubadam25...@gmail.com> wrote:
> Hi,
>
> Take this data into DataSet and then bind data View using this dataset.
>

shakthi

unread,
Jul 7, 2007, 1:18:12 AM7/7/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
If i use readXml() iam getting an error call there is no Data found of
type System.XMl.XMLReader..........

When i invoke GetInfoByZip("49544")....it returns...


<?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 tried storing this in an string array but it
is not working to......iam still thinking on how to take the data into
a dataset???....

Charles A. Lopez

unread,
Jul 7, 2007, 4:10:43 PM7/7/07
to DotNetDe...@googlegroups.com
you have snippets of the code already...
 
GetInfoByZip("XXXXX")
 
process the output of that.
 
Re-Read your original code. You are missing something that is obvious to me.


 
charle...@gmail.com

Is your ARM out of control? Let me FIX it for you! (e-mail charle...@gmail.com for the BEST RATES - Mention Code - ARMFIX - WSMB). - WSMB

Enterprise Managed Desktop Computing - By Charles A. Lopez (e-mail charle...@gmail.com - Mention CODE DEWEYADAMS)

Project Management - Professional Software Development - Feasibility Studies as low as $199 USD (email charle...@gmail.com mention CODE MANPOWER7)

DEVELOPERS WANTED - EMAIL WITHIN

shakthi

unread,
Jul 9, 2007, 4:07:46 PM7/9/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
HI....

Iam not missing something but iam not getting how to convert this XML
file to DataTable.........

when i pass a value in GetInfoByZip("xxx") and tryprinting in console
i am getting an XML(data comes from webservice)..i.e.

<?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>

but i want this data tobe displayed in datatable.......i tried using
DataTable.Readxml()...but it is not working....iam stucked!!!!

On Jul 7, 4:10 pm, "Charles A. Lopez" <charlesalo...@gmail.com> wrote:
> you have snippets of the code already...
>
> GetInfoByZip("XXXXX")
>
> process the output of that.
>
> Re-Read your original code. You are missing something that is obvious to me.
>

> --
> Charles A. Lopez
> charlesalo...@gmail.com


>
> Is your ARM out of control? Let me FIX it for you! (e-mail

> charlesalo...@gmail.com for the BEST RATES - Mention Code - ARMFIX - WSMB).


> - WSMB
>
> Enterprise Managed Desktop Computing - By Charles A. Lopez (e-mail

> charlesalo...@gmail.com - Mention CODE DEWEYADAMS)


>
> Project Management - Professional Software Development - Feasibility Studies

> as low as $199 USD (email charlesalo...@gmail.com mention CODE MANPOWER7)
>
> DEVELOPERS WANTED - EMAIL WITHIN- Hide quoted text -
>
> - Show quoted text -

Cerebrus

unread,
Jul 9, 2007, 11:28:16 PM7/9/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Your GetInfoByZip method appears to return a string. Which is why I
suggested that you use that string as an argument to the
Dataset.ReadXml() method. Unless I'm much mistaken, this overload
should exist even on the compact framework.


shakthi

unread,
Jul 10, 2007, 2:14:55 PM7/10/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
When iam trying to assgin the GetInfoByZip() to a string..iam getting
an error that cannot convert Xml.XMLNode to String....
because ReadXml() doesnot take an XMLNode type of arugument!!.....

Sukhesh

unread,
Jul 31, 2007, 7:31:43 AM7/31/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

If ur method GetInfoByZip() is returning xml as string type, u can do
the following

Dim str As String
Dim strStream As System.IO.StreamReader
Dim ds As DataSet
Dim dt As DataTable
ds = New DataSet

str = GetInfoByZip()
strStream = GetSR(str)
ds = New DataSet
ds.ReadXml(strStream) //Takes StreamReader object as parameter
dt = ds.Tables("Table")
DataGrid1.DataSource = dt
DataGrid1.DataBind()

//Function to convert string to StreamReader object
Public Function GetSR(ByVal Input As String) As StreamReader
GetSR = New StreamReader(New MemoryStream(New
ASCIIEncoding().GetBytes(Input)))
End Function

> > should exist even on the compact framework.- Hide quoted text -

Sammy Lin

unread,
Jul 31, 2007, 4:16:32 PM7/31/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
XmlNode has a method called OuterXml (returns string) which gives you
the XML for that node, which lets you avoid using Streams.
What Cerebrus and Sukhesh is suggesting is that you should take the
output from GetInfoByZip convert it to string and pass that string to
DataSet's LoadXml method. Then you can do whatever you want with that
DataSet.

The one thing I dont like about this whole XML straight into the
database is that if the XML changes, your datamodel will need to
change. I would rather write a parser for the XML which returns a
DataTable or DataSet (whichever you like) which then could be pushed
to your DB. If the XML changes, all you need to do is change the
parser.

Alexander Higgins

unread,
Aug 1, 2007, 9:28:04 PM8/1/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
If you can't figure out how to do it it via dataset.readxml like
this...
Dim XmlDoc as XmlDocument = GetInfoByZip()
Dim DS as new Data.DataSet
DS.ReadXML(XmlDoc.outerXML.ToString)
Dim DT as Data.DataTable = DS.Tables(0)

Then parse the table manually ', Note this is a basic example and you
need to add error checking


Dim TableNode as XmlNodeLIst = Node.SelectNodes("NewDataSet/Table")
Dim DT as new Data.DataTable
For I as integer = 0 to TableNode.ChildNodes.Count -1
DT.Columns.Add(TableNode.ChildNodes(i).Name.ToString)
Next
Dim Row as Data.DataRow = DT.NewRow
For I as integer = 0 to TableNode.ChildNodes.Count -1
Row(TableNode.ChildNodes(i).Name.ToString) =
TableNode.ChildNodes(i).InnerXml.ToString
Next
DT.Rows.Add(Row)


Alexander Higgins
http://alexanderhiggins.com

> > > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages