<?xml version="1.0" encoding="utf-8"?> <PathList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Path> <PathName>PM_CableLoss</PathName> <PathID>1</PathID> <AdditionalLoss>0</AdditionalLoss> <Cal_Date>4/7/2010 3:58 PM</Cal_Date> <TesterID>TesterA</TesterID> <CalCable_PathName>CAL_CABLE</CalCable_PathName> <UseCalCable>true</UseCalCable> <DataList> <Data> <Frequency>2412</Frequency> <Value>10.7</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2417</Frequency> <Value>10.7</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2422</Frequency> <Value>10.8</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2427</Frequency> <Value>10.9</Value> <Delta>0.0</Delta> </Data> </DataList> </Path> <Path> <PathName>Test_CableLoss</PathName> <PathID>2</PathID> <AdditionalLoss>0</AdditionalLoss> <Cal_Date>4/7/2010 3:58 PM</Cal_Date> <TesterID>TesterB</TesterID> <CalCable_PathName>CAL_CABLE</CalCable_PathName> <UseCalCable>true</UseCalCable> <DataList> <Data> <Frequency>2412</Frequency> <Value>0</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2417</Frequency> <Value>0</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2422</Frequency> <Value>0</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2427</Frequency> <Value>0</Value> <Delta>0.0</Delta> </Data> <Data> <Frequency>2432</Frequency> <Value>0</Value> <Delta>0.0</Delta> </Data> </DataList> </Path> </PathList>
上面的XML经过在线转换工具转换,又手动添加后得到以下效果的实体类,但问题是调用有错误,不能体现节点组的关系,请求修改,或者帮忙推荐教程,谢谢!
using System; using System.Xml.Linq; using System.Xml.Serialization; //XmlRoot 根节点 [XmlRoot(ElementName = "PathList")] public class PathList { [XmlElement(ElementName = "Path")] public Path Path { get; set; } } public class Path { [XmlElement(ElementName = "PathName")] public string PathName { get; set; } [XmlElement(ElementName = "PathID")] public int PathID { get; set; } [XmlElement(ElementName = "AdditionalLoss")] public string AdditionalLoss { get; set; } [XmlElement(ElementName = "Cal_Date")] public string Cal_Date { get; set; } [XmlElement(ElementName = "TesterID")] public int TesterID { get; set; } [XmlElement(ElementName = "CalCable_PathName")] public string CalCable_PathName { get; set; } [XmlElement(ElementName = "UseCalCable")] public string UseCalCable { get; set; } [XmlElement(ElementName = "DataList")] public DataList DataList { get; set; } } public class DataList { [XmlElement(ElementName = "Data")] public Data Data { get; set; } } public class Data { [XmlElement(ElementName = "Frequency")] public string Frequency { get; set; } [XmlElement(ElementName = "Value")] public string Value { get; set; } [XmlElement(ElementName = "Delta")] public string Delta { get; set; } }
你在vs上 点编辑->选择性粘贴->将xml粘贴为类
他就行了不行你找微软讨公道.
受教了,居然还有这功能啊!
正在找原因,有此菜单,但功能无效!
1 public class PathList 2 { 3 [XmlElement(ElementName = "Path")] 4 public List<Path> Path { get; set; } 5 }
不错,谢谢!