简体   繁体   中英

How can RestSharp deserialize this Xml?

Is it possible to get RestSharp to deserialize this Xml snippet, into a single class, instead of two classes?

<shippingInfo>
    <shippingServiceCost currencyId="AUD">58.02</shippingServiceCost>
    <shippingType>Flat</shippingType>
    <shipToLocations>Worldwide</shipToLocations>
</shippingInfo>

Notice the first element shippingServiceCost ? it has an attribute there. Normally, I would just create a child class called ShippingServiceCost and add two properties in there: CurrentId and Value .

But it it possible to have the CurrencyId value in a property, in the main class ShippingInfo ?

The way I would do it, could be:

  1. crafting a small XSLT file that does what you want to transform the orginal xml to the new structure
  2. extend the default RestSharp XmlSerializer to apply the XSLT transformation after the normal serialization output
  3. register the new XmlSerializer to the restsharp client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM