简体   繁体   中英

LINQ Writing HTML as XML

I am new to web programming and Visual Web Developer. I have made a page that prompts the user for input and then this input replaces the prompts using InnerHTML accesses. 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. So I need a way to write the edits out to an XML file. I understand that this can be done with LINQ but I haven't figured out how to do it.

Any advice is appreciated.

Regards.

Here's an example I found online at: 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.

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");

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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