为什么 msdn说 XmlSerializer 无法反序列化以下数组:ArrayList 的数组和 List<(Of <(T>)>) 的数组?

lindping 2008-12-15 02:00:05
我是做.net的。

我尝试过,可以把List<T> 直接序列化和反序列化啊。

还有一个问题是,我读取到的xml是这种格式 "<root> <item><a>1</a><b>2</b></item> <item><a>3</a><b>4</b></item> </root>"
请问建一个什么样的类来反序列化好呢?
...全文
148 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
一品梅 2008-12-16
  • 打赏
  • 举报
回复
楼主,前一段时间我在看web2.0高级编程,里面涉及到XML知识蛮多的.关于你的问题,有如下代码,楼主可以参考:
using System;
using System.Xml.Serialization;

[XmlRoot("book")]
public class Book{
[XmlElement("author")]
public string author;

public Book(){}

public Book(string author){
this.author=author;
}
}
/*这个类包含形式为[XmlRoot()]和[XmlElement()]的说明,XmlSerializer类将利

用这些说明:
*/
<%@ WebHandler Language="c#" Class="TestHttpHandler2" %>
using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

public class TestHttpHandler2:IHttpHandler{
public void ProcessRequest(HttpContext context){
//String containing the author name
string author=context.Request.QueryString.Get("author");
//outputStream to serialize the result to
stream outputStream=context.Response.OutputStream;

//Set resulting content type
context.Response.ContentType="application/xml";
//Create Book instance and serialize it
Book book=new Book(author);
Xmlserializer xmlSerializer=new XmlSerializer(typeof(Book));
xmlserializer.Serialize(outputStream,book);
}

public bool IsReusable{ get {return true;} }
}


因为没有光盘,我就照书一点点敲的,因为想把它发表到我的博客上 :)
lindping 2008-12-15
  • 打赏
  • 举报
回复
我所获取到的xml不是来自我自己序列化出来的,而是从另一方提供过来的
街头小贩 2008-12-15
  • 打赏
  • 举报
回复
.net不太熟!java的序列化倒是懂点!你没有序列化怎么能反序列化呢?

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧