How to map XML to .NET class?

Z

Zean Smith

I was given an XML (see below) already in string format, is it possible to
map the data to an Array of a .NET class? I read some article about
XMLDataDocument and XMLReader, but never talk about mapping... help.

It would be cool if I can get data fill out like this from XML..

((myclass)array[0]).title; // returns "Microsoft"
((myclass)array[0]).revenue; // returns "18621.85"

I know write my own .NET ASMX web services, of course I will return a
DataSet. but I don't know how to deal with Apache SOAP, any help or tips is
appreciated.

Thanks

Zean


<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:namesp2="http://xml.apache.org/xml-soap"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<namesp1:getSalesGrossesResponse
xmlns:namesp1="urn:Company/SOAP/Dispatcher">
<SOAP-ENC:Array SOAP-ENC:arrayType="namesp2:SOAPStruct[2]"
xsi:type="SOAP-ENC:Array">
<item xsi:type="namesp2:SOAPStruct">
<TITLE_NAME xsi:type="xsd:string">Microsoft</TITLE_NAME>
<REVENUE xsi:type="xsd:float">18621.85</WEEKEND_REV>
</item>
<item xsi:type="namesp2:SOAPStruct">
<TITLE_NAME xsi:type="xsd:string">Oracle</TITLE_NAME>
<REVENUE xsi:type="xsd:float">16326.86</WEEKEND_REV>
</item>
</SOAP-ENC:Array>
</namesp1:getSalesGrosses>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 
K

Kevin Spencer

Create a class that can be deserialized from the XML.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
J

jens Jensen

Does this mean, you never may need to write an xml schema in .Net in order
to write a webservice that exchange complex data types?
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top