简体   繁体   English

LINQ将HTML编写为XML

[英]LINQ Writing HTML as XML

I am new to web programming and Visual Web Developer. 我是Web编程和Visual Web Developer的新手。 I have made a page that prompts the user for input and then this input replaces the prompts using InnerHTML accesses. 我制作了一个页面,提示用户输入,然后此输入使用InnerHTML访问替换了提示。 Thus the table can only be edited the first time it is displayed. 因此,该表只能在第一次显示时进行编辑。 It is the final, edited version of the HTML that I want others to be able to access. 它是我希望其他人能够访问的HTML的最终版本。 So I need a way to write the edits out to an XML file. 因此,我需要一种将编辑内容写出到XML文件的方法。 I understand that this can be done with LINQ but I haven't figured out how to do it. 我知道这可以使用LINQ来完成,但是我还没有弄清楚该怎么做。

Any advice is appreciated. 任何建议表示赞赏。

Regards. 问候。

Here's an example I found online at: http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx . 这是我在以下网址在线找到的示例: http : //www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx You should be able to figure it out if you compare the LINQ to XML code with the file output. 如果将LINQ to XML代码与文件输出进行比较,您应该能够弄清楚。

Code: 码:

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"); doc.Save(@“ c:\\ sample.xml”);

file: 文件:

<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>

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

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