I'm in the process of deserializing into C# objects a custom inflexible XML schema to traverse and migrate the data within.
A brief example:
<Source>
...
<Provider>
<![CDATA[read 1]]>
<Identifier><![CDATA[read 2]]></Identifier>
<IdentificationScheme><![CDATA[read 3]]></IdentificationScheme>
</Provider>
...
</Source>
I'm looking the deserialize the Provider element with the first CDATA element value, read 1
, and it's sibling element values too, read 2
and read 3
.
Using http://xmltocsharp.azurewebsites.net/ it produces the following objects:
[XmlRoot(ElementName = "Provider")]
public class Provider
{
[XmlElement(ElementName = "Identifier")]
public string Identifier { get; set; }
[XmlElement(ElementName = "IdentificationScheme")]
public string IdentificationScheme { get; set; }
}
[XmlRoot(ElementName = "Source")]
public class Source
{
[XmlElement(ElementName = "Provider")]
public Provider Provider { get; set; }
}
But it fails to account for the the CDATA value, in fact I think deserializing it like this the value would not be reachable.
I think this maybe also be related to the XmlDeserializer to use, I was planning on RestSpharp
's (as it's a library to the website already) or System.Xml.Link.XDocument
, but I'm not sure whether either can handle this scenario?
In my searches I couldn't find an example either, but stack did suggest this <!{CDATA[]]> and <ELEMENT> in a xml element that is precisely the same schema option.
Thanks so much for any help in advance,
EDIT 1
As far as I can tell the [XmlText]
is the solution required, as pointed out in Marc Gravell's answer below, but it does not work/is implemented on RestSharp's XmlDeserializer, but further testing would be required to ascertain that for sure.
>(response)`, time to try the default one :D
– Pedro Costa Apr 07 '18 at 17:07