OK, a challenge to the deep thinkers out there:
My soap server sends me XML that looks sort of like this:
<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:xxxxxx="...">
<...bunch of soap header stuff.../>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<queryResponse xmlns="...">
<resultSet seqNo="0">
<Types>
<name>varchar</name>
<value>varchar</value>
</Types>
<row>
<name>field1</name>
<value>0</value>
</row>
<row>
<name>field2</name>
<value>some string value</value>
</row>
<row>
<name>field3</name>
<value>false</value>
</row>
<... repeats for many more rows... />
</resultSet>
</queryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I take the <row>
nodes and populate the following class:
public class SessionProperties
{
public int IntField {get;set;}
public string StringField {get;set;}
public bool BooleanField {get;set;}
// more fields...
}
I want to avoid manually populating the SessionProperties
instance, e.g.,
var myProps = new SessionProperties();
myProps.IntField = XElement("...").Value; // I don't want to do this!
I'd like to write a "generic" set of code which can populate the SessionProperties instance without having to hardcode the class properties to a specific XML node.
Also I don't want to write an IXmlSerializable implementation, I think that will only make the code more complex. Let me know if I'm wrong though.
Finally, the soap server may send me additional row nodes in the future, and all I'd like to do is just update the SessionProperties
class if at all possible. Is there some generic approach (perhaps using custom attributes, etc.) which can accomplish this?
Thanks in advance!