我有这样的XML:DataContract反序列化XML
<ResultData xmlns="http://schemas.datacontract.org/2004/07/TsmApi.Logic.BusinesEntities"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Information>Schedule added.</Information>
<Success>true</Success>
</ResultData>
有没有办法让作为结果只有:
<ResultData>
<Information>Sched added.</Information>
<Success>true</Success>
</ResultData>
没有从下面的示例中,所有其他的事情? 因为当我尝试获取下面显示的结果字符串的对象时,它不起作用。
Datacontract XML serialization
我尝试使用的代码是:
var serializer = new XmlSerializer(typeof(ResultData));
var rdr = new StringReader(xmlResultString);
var resultingMessage = (ResultData)serializer.Deserialize(rdr);
并在最后一排它为我的错误:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Additional information: There is an error in XML document (1, 2).
<ResultData xmlns='http://schemas.datacontract.org/2004/07/TsmApi.Logic.BusinesEntities'> was not expected.
ResultData:
[DataContract]
public class ResultData
{
[DataMember]
public bool Success
{
get;
set;
}
[DataMember]
public string Information
{
get;
set;
}
}
显示你的代码并定义“不起作用”,否则你很可能无法得到帮助是零。我们不是clairvoyants .... – Tim 2014-11-01 09:15:12
我编辑了我的问题。谢谢。 – dillci 2014-11-01 14:56:47
@dillci Again ... ResultData类在哪里? – Aron 2014-11-01 15:42:18