470,848 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

How to map XML to .NET class?

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>


Apr 27 '06 #1
2 1255
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.

"Zean Smith" <no****@nospamaaamail.com> wrote in message
news:44**********************@news.astraweb.com...
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>

Apr 27 '06 #2
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?

Apr 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fernando Rodriguez | last post: by
18 posts views Thread by John M. Gabriele | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
8 posts views Thread by Bryan Parkoff | last post: by
21 posts views Thread by Jon Slaughter | last post: by
5 posts views Thread by Andy | last post: by
3 posts views Thread by Hamilton Woods | last post: by
reply views Thread by emin.shopper | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.