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 の観点からは、むしろ正しくありません (1 つのタグに複数のデータが含まれる)。今、私はこのようなことを試みています:
<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>
そして、2 つの疑問が生じます: 1. これは配列を表す正しい形式ですか? 2. このデータを LINQ クエリで読み取って、配列に解析できるようにする方法を教えてください。