0

私は Web プログラミングと Visual Web Developer の初心者です。ユーザーに入力を求めるページを作成しました。この入力は、InnerHTML アクセスを使用してプロンプトを置き換えます。したがって、テーブルは最初に表示されたときにのみ編集できます。他の人がアクセスできるようにしたいのは、最終的に編集された HTML のバージョンです。そのため、編集内容を XML ファイルに書き出す方法が必要です。これは LINQ で実行できることは理解していますが、その方法がわかりません。

アドバイスをいただければ幸いです。

よろしく。

4

1 に答える 1

0

これが私がオンラインで見つけた例です: http ://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx 。LINQ to XMLコードをファイル出力と比較すると、それを理解できるはずです。

コード:

XDocument doc = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XElement("rss", 
        new XAttribute("version", "2.0"),
        new XElement ("channel",
            new XElement("title", "RSS Channel Title"),
            new XElement("description", "RSS Channel Description."),
            new XElement("link", "http://aspiring-technology.com"),
                new XElement("item",
                new XElement("title", "First article title"),
                new XElement("description", "First Article Description"),
                new XElement("pubDate", DateTime.Now.ToUniversalTime()),
                new XElement("guid", Guid.NewGuid())),
            new XElement("item",
                new XElement("title", "Second article title"),
                new XElement("description", "Second Article Description"),
                new XElement("pubDate", DateTime.Now.ToUniversalTime()),
                new XElement("guid", Guid.NewGuid()))
            )
        )
     );

doc.Save(@ "c:\ sample.xml");

ファイル:

<rss version="2.0">
  <channel>
    <title>RSS Channel Title</title>
    <description>RSS Channel Description.</description>
    <link>http://aspiring-technology.com</link>
    <item>
      <title>First article title</title>
      <description>First Article Description</description>
      <pubDate>2006-12-05T20:53:53.53125</pubDate>
      <guid>ff7bbf19-9155-4773-913c-767bcbf09904</guid>
    </item>
    <item>
      <title>Second article title</title>
      <description>Second Article Description</description>
      <pubDate>2006-12-05T20:53:53.5625</pubDate>
      <guid>8a3fd5e8-b99f-49fe-8a43-7fb62d80c18c</guid>
    </item>
  </channel>
</rss>
于 2012-06-12T17:57:18.067 に答える