<A xmlns="http://www.aaa.com/bbb/"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<B>
<aa>AUH</aa><bb>5</bb><cc>Abu</cc>
</B>
<B>
<aa>AUH</aa><bb>7</bb><cc>ghi</cc>
</B>
<ServiceResponse><ErrorMessage i:nil="true"/><ExecutionStatus>SUCCESS</ExecutionStatus></ServiceResponse>
</A>
我有一个类似于上面的XML,并且为A,B和ServiceResponse创建了类。在Windows Phone 7中解析XML
,我试图使用下面的代码来解析:
XmlSerializer ser = new XmlSerializer(typeof(A));
objAirportListResponse = ser.Deserialize(new StringReader(str)) as A;
在上面的代码中“STR”是其含有以上XML字符串。
我越来越感到错误象下面这样:
有XML文档中的误差(1,2)(System.InvalidOperationException)
如果删除了的xmlns =“HTTP:// www.aaa.com/bbb/“xmlns:i =”http://www.w3.org/2001/XMLSchema-instance“从XML我得到了相同的错误在 由于i:nil =”true“ 。然后我删除了xmlns =“http://www.aaa.com/bbb/”xmlns:i =“http://www.w3.org/2001/XMLSchema-instance”和i:nil =“true”我试过解析XML,这次它成功解析到类中。
但删除xmlns =“http://www.aaa.com/bbb/”xmlns:i =“http://www.w3.org/2001/XMLSchema-instance”和i:nil =“true “是不是一个正确的方式,请帮助我如何解析上面的例子。
在此先感谢。
而* *是什么例外? `InvalidOperationException.Message`和`InvalidOperationException.InnerException`可能会告诉你到底发生了什么问题。 – Will 2011-12-16 14:35:28