C# と LINK to XML を使用して、「xVar」と呼ばれる変数から生成されるこの「フラットな」XML ファイル
<vWorkflows>
<vSection sectionTitle="Bars" sectionId="4">
<vCategory catTitle="Between Visits" catRef="13">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder1</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-01 00:00:00</pubDate>
<lastUpdate>2012-05-18 00:00:00</lastUpdate>
</link>
</type>
</vCategory>
</vSection>
<vSection sectionTitle="Pre-Visit" sectionId="1">
<vCategory catTitle="Scheduling" catRef="4">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder2</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-02 00:00:00</pubDate>
<lastUpdate>2012-05-19 00:00:00</lastUpdate>
</link>
</type>
</vCategory>
</vSection>
<vSection sectionTitle="Patient Visit" sectionId="2">
<vCategory catTitle="Check-in" catRef="5">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder3</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-03 00:00:00</pubDate>
<lastUpdate>2012-05-20 00:00:00</lastUpdate>
</link>
</type>
</vCategory>
</vSection>
<vSection sectionTitle="Patient Visit" sectionId="2">
<vCategory catTitle="Check-in" catRef="5">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder4</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-04 00:00:00</pubDate>
<lastUpdate>2012-05-21 00:00:00</lastUpdate>
</link>
</type>
</vCategory>
</vSection>
<vSection sectionTitle="Bars" sectionId="4">
<vCategory catTitle="Registration" catRef="3">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder5</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-05 00:00:00</pubDate>
<lastUpdate>2012-05-22 00:00:00</lastUpdate>
</link>
</type>
</vCategory>
</vSection>
</vWorkflows>
...のように見える必要があります
<workflows>
<section sectionTitle="Bars" sectionId="4">
<category catTitle="Between Visits" catRef="13">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder1</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-01 00:00:00</pubDate>
<lastUpdate>2012-05-18 00:00:00</lastUpdate>
</link>
</type>
</category>
<category catTitle="Registration" catRef="3">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder5</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-05 00:00:00</pubDate>
<lastUpdate>2012-05-22 00:00:00</lastUpdate>
</link>
</type>
</category>
</section>
<section sectionTitle="Patient Visit" sectionId="2">
<category catTitle="Check-in" catRef="5">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder3</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-03 00:00:00</pubDate>
<lastUpdate>2012-05-20 00:00:00</lastUpdate>
</link>
</type>
</category>
<category catTitle="Check-in" catRef="5">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder4</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-04 00:00:00</pubDate>
<lastUpdate>2012-05-21 00:00:00</lastUpdate>
</link>
</type>
</category>
</section>
<section sectionTitle="Pre-Visit" sectionId="1">
<category catTitle="Scheduling" catRef="4">
<type typeTitle="" typeRef="">
<link linkNum="">
<linkTitle>placeholder2</linkTitle>
<linkSummary></linkSummary>
<linkKeywords></linkKeywords>
<pubDate>2012-05-02 00:00:00</pubDate>
<lastUpdate>2012-05-19 00:00:00</lastUpdate>
</link>
</type>
</category>
</section>
</workflows>
次のように動作しますが、最初の「グループ化」ですべての属性を取得しようとして頭がぼんやりし、必然的に続く他のグループ化を追加する方法がわかりません。
XDocument xDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("XML Source Data for Dial Flash"),
new XElement("workflows",
from sec in xVar.Elements("vSection")
//group sec by (string)sec.Attribute("sectionTitle").Value,
group sec by (string)sec.Attribute("sectionTitle").Value into gsec
select new XElement("section",
new XAttribute("sectionTitle", gsec.Key)
)
)
);
これを行うより良い方法はありますか?プロセスで日付を MM/dd/yyyy に変換できる場合のボーナス...