繁体   English   中英

以XML存储数组/使用LINQ读取数组

[英]Storing array in XML/reading it with LINQ

我正在尝试使用LINQ获得表示特定城市之间距离的2D数组。 由我来选择问题的适当XML表示形式。 首先,我使用MatLAB样式的数组表示依赖关系,如下所示:

<cityMap>
      [-, 2, 3, 4, 5, 6, 7, 8; 
          1, -, 3, 4, 5, 6, 7, 8;
          1, 2, -, 4, 5, 6, 7, 8;
          1, 2, 3, -, 5, 6, 7, 8;
          1, 2, 3, 4, -, 6, 7, 8;
          1, 2, 3, 4, 5, -, 7, 8;
          1, 2, 3, 4, 5, 6, -, 8;
          1, 2, 3, 4, 5, 6, 7, -]
</cityMap>

从单个LINQ查询中获取此矩阵并用C#解析它非常方便,但是从XML的角度来看,它是不正确的(一个标签中有多个数据)。 现在,我正在尝试这样的事情:

<salesman>
  <salesmanNumber>10</salesmanNumber>
  <cities>
    <city id="1">
      <headquarter>1</headquarter>
      <distance toCity="2">2</distance>
      <distance toCity="3">3</distance>
      <distance toCity="4">4</distance>
      <distance toCity="5">5</distance>
      <distance toCity="6">6</distance>
    </city>
    <city id="2">
      <headquarter>1</headquarter>
      <distance toCity="1">1</distance>
      <distance toCity="3">3</distance>
      <distance toCity="4">4</distance>
      <distance toCity="5">5</distance>
      <distance toCity="6">6</distance>
               [....]
  </cities>
</salesman>

然后出现两个问题:1.这种表示数组的正确形式吗? 2.如何使用LINQ查询读取此数据,以便能够将其解析为数组?

是否需要XML? 二维数组更自然地映射到Excel文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM