首页新闻找找看学习计划

用在线工具转换的实体类好像用不了,网上资料好少啊。

0
悬赏园豆:10 [已解决问题] 解决于 2017-05-24 14:08
<?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; }
}
复制代码

 

 

TabZ的主页 TabZ | 初学一级 | 园豆:36
提问于:2017-05-24 11:34
< >
分享
最佳答案
0

你在vs上 点编辑->选择性粘贴->将xml粘贴为类

他就行了不行你找微软讨公道.

收获园豆:6
吴瑞祥 | 高人七级 |园豆:28729 | 2017-05-24 13:16

受教了,居然还有这功能啊!

 

正在找原因,有此菜单,但功能无效!

TabZ | 园豆:36 (初学一级) | 2017-05-24 13:45
其他回答(1)
0
1 public class PathList
2 {
3     [XmlElement(ElementName = "Path")]
4     public List<Path> Path { get; set; }
5 }
收获园豆:4
~扎克伯格 | 园豆:1799 (小虾三级) | 2017-05-24 13:17

不错,谢谢!

支持(0) 反对(0) TabZ | 园豆:36 (初学一级) | 2017-05-24 13:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册