<?xml version="1.0" encoding="utf-8" ?> <htmlPages> <htmlPage name="home"> <cssList> <css name ="base.css"></css> <css name ="font.css"></css> </cssList> <javascripts> <javascript name="jquery"></javascript> <javascript name="jquery.ui"></javascript> </javascripts> </htmlPage> <htmlPage name="about"> <cssList> <css name ="base2.css"></css> <css name ="font2.css"></css> </cssList> <javascripts> <javascript name="jquery2"></javascript> <javascript name="jquery2.ui"></javascript> </javascripts> </htmlPage> </htmlPages>
Launcher的代码写的不全,我没弄出来。
按照wny的方法生成的代码也无法直接序列化,有错,好像生成的代码本身就有问题,还好,网上有人遇到过这种问题,手动删掉了把二维数组改成一维数组,就好了。
你可以使用VS先获得XML文件的架构定义XSD文件,通过xsd.exe工具自动生成可用于反序列化的C#类文件……
还有这方法?回去试下,如果能行,你就帮了我一个大忙,我有一堆XML文件需要反序列化,我正在想着怎么办呢
class htmlPage{ [xmlattribute]string name; List<css> cssList;List<javascript> javascripts;}
class css {[xmlattribute]string name;}
class javascript{[xmlattribute]string name;}
这个不对啊
public class htmlPage { [XmlAttribute] public string name { get; set; } [XmlAttribute("cssList")] [XmlArray("css")] public List<css> cssList { get; set; } [XmlAttribute("javascripts")] [XmlArray("javascript")] public List<javascript> javascripts { get; set; } } public class css { [XmlAttribute] public string name { get; set; } } public class javascript { [XmlAttribute] public string name { get; set; } }
var fs = new FileStream(string.Format(@"{0}\test.xml", Environment.CurrentDirectory), FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(htmlPage[])); var htmlPages = serializer.Deserialize(fs);
哪里有错误吗?
@沧海一杰: XmlSerializer serializer = new XmlSerializer(typeof(List<htmlPage>));
public Class MyClass
{
list<string> csslist{get;set;};
list<string>javascripts{get;set;};
}