LorneCash
LorneCash

Reputation: 1604

Can Servicestack Deserialize XML without namespaces

I'm familiar with these two methods:

var newDataSet = XmlSerializer.DeserializeFromString<NEWDATASET>(xmlDoc.OuterXml);
var newDataSet = xmlDoc.OuterXml.FromXml<NEWDATASET>();

But they both give me the same error:

DeserializeDataContract: Error converting type: Error in line 1 position 40. Expecting element 'NEWDATASET' from namespace ''.. Encountered 'Element' with name 'NEWDATASET', namespace ''.

I feel like there should be a way to get this to work as long as the the element names either match the public property names or the DataMemberAttribute Name parameter of the public property was set to the element name.

Upvotes: 1

Views: 177

Answers (1)

mythz
mythz

Reputation: 143319

ServiceStack doesn't have it's own XML Serializer, it's DataContractSerializer uses .NET's XML DataContract and its XmlSerializer uses .NET's XmlSerializer. So the XML payload would need to be deserialized from either of those BCL implementations.

An alternative way to parse arbitrary XML is to use XLinq and ServiceStack's XLinqExtensions which provide UX-friendly helpers to simplify XML parsing.

Here are some examples for parsing arbitrary XML with XLinq and helpers:

Upvotes: 1

Related Questions