p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 3.5 SP1 Edition: In C# and VB (http://p2p.wrox.com/forumdisplay.php?f=497)
-   -   Creating XML with Linq To XML (http://p2p.wrox.com/showthread.php?t=81904)

AnujAngural December 13th, 2010 12:32 PM

Creating XML with Linq To XML
 
Hello friends,
I am new to XML,so please help me out [:D]

Following is my code-->

try
{
Response.ContentType = "text/xml";

XNamespace ns = "http://example.books.com";
XDocument books = new XDocument(new XElement(ns + "bookstore",
new XElement(ns + "book",
new XAttribute("publication", "pub123"),
new XAttribute("ISBN", "123"),
new XElement(ns + "Title", "ASP.NET 4.0"),
new XElement(ns + "Price", "Rs 100"),
new XElement(ns + "Author",
new XElement(ns + "First-Name", "Anuj"),
new XElement(ns + "Last-Name", "Angural")))));


Response.Write(books);

}
catch (Exception ex)
{
Response.Write(ex.Message);

}

I am getting following error in IE--->

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource 'http://localhost:3018/XML/Default2.aspx'....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&...


All times are GMT -4. The time now is 02:17 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.