C# XML类 无法解析XML字符串。求教大神!求教SP1234,该怎么解决

C# XML类 无法解析XML字符串。求教大神!求教SP1234
本帖最后由 ittxl 于 2014-09-02 12:51:54 编辑
//无法正确解析。求正确类的写法。本人各种自学。学艺不精。求大神指导。求教SP1234。我现在在做一个根据XML生成类文件的东东。就是解析例子弄不好。求教。

XML a 结构


/*
<?xml version="1.0" ?>
<humanResource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" record="2">
<worker number="001">
<infoItem name="name">Michale</infoItem>
<infoItem name="sex">male</infoItem>
<infoItem name="age">25</infoItem>
</worker>
<worker number="002">
<infoItem name="name">Surce</infoItem>
<infoItem name="sex">male</infoItem>
<infoItem name="age">28</infoItem>
</worker>
</humanResource>
*/
public  void tescXML()
{
string xmlaaa="<?xml version=\"1.0\" ?><humanResource xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" record=\"2\"><worker number=\"001\"><infoItem name=\"name\">Michale</infoItem><infoItem name=\"sex\">male</infoItem><infoItem name=\"age\">25</infoItem></worker><worker number=\"002\"><infoItem name=\"name\">Surce</infoItem><infoItem name=\"sex\">male</infoItem><infoItem name=\"age\">28</infoItem></worker></humanResource>";

string xmlbbb="<pnrinfo><code>0</code><pnr>aabbcc</pnr><air>HU</air><pnrsrcid></pnrsrcid><message>网站提示</message></pnrinfo>";
aaa  clsaaa= JsonXmlHelper.XMLDeserialize<aaa>(xmlaaa);
bbb  clsbbb = JsonXmlHelper.XMLDeserialize<bbb>(xmlbbb);

}
        public static T XMLDeserialize<T>(string xmlObj)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            using (StringReader reader = new StringReader(xmlObj))
            {
                return (T)serializer.Deserialize(reader);
            }

        }





public class aaa
{

public humanResource_ humanResource { get; set; }
[Serializable]
public class humanResource_ 

[XmlAttribute]
public string record { get; set; }
public List<worker_> worker { get; set; }
[Serializable]
public class worker_ 

[XmlAttribute]
public string number { get; set; }
public List<infoItem_> infoItem { get; set; }
[Serializable]
public class infoItem_ 

[XmlAttribute]
public string name { get; set; }
public string #text { get; set; } 


}
}







public class bbb
{

        public pnrinfo_ pnrinfo { get; set; }
        [Serializable]
        public class pnrinfo_
        {
            public string code { get; set; }
            public string pnr { get; set; }
            public string air { get; set; }
            public string pnrsrcid { get; set; }
            public string message { get; set; }
        }

}





------解决方案--------------------
你这怎么还有Json,你对着下面这篇文章做一遍就是了
http://www.cnblogs.com/zhchongyao/archive/2009/08/11/1543458.html
------解决方案--------------------
到底怎么个无法解析?如果是报错,就说明一下哪行出错,错误的信息是什么,如果是没有达到预期的效果,把现象说清楚来。唉,不把问题描述清楚怎么叫人帮你解决?

PS:撸主准备好你的小心脏
------解决方案--------------------
难不成 你不知道 linq  to  xml。
http://blog.csdn.net/duanzi_peng/article/details/24018431
------解决方案--------------------
本帖最后由 bdmh 于 2014-09-02 13:13:17 编辑

        public static T XMLDeserialize<T>()
        {