CHAPTER 12 (Web hosting asp) CASE STUDY: USING .NET FOR

CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION 371 Figure 12-6. Handling updating errors The next subroutine, GridViewDeleted, is similar: Sub GridViewDeleted(ByVal s As Object, ByVal e As GridViewDeletedEventArgs) If Not e.Exception Is Nothing Then lblError.Text = “
  Error: Could not delete row” e.ExceptionHandled = True End If End Sub Again, the page displays an error if it can t delete a row. The code block also contains a subroutine called addNews. This subroutine handles the Add News button click event: Sub addNews(sender As Object, e As System.EventArgs) response.redirect(“addNews.aspx”) end sub When users click the Add Newsbutton, the browser redirects to the addNews.aspx page. The page adds new content to the database.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

368 CHAPTER 12 CASE STUDY: USING (Submit web site) .NET

368 CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION manageNews.aspx The manageNews.aspx page displays the content from the database in a GridView control, as shown in Figure 12-5. Notice that the control renders as a table. Figure 12-5. The manageNews.aspx page The news items display in a table. Each column represents a field from the news table. The table headings are links that you can click to sort the columns. This page also includes automatically generated Edit and Delete links. Users need to click the Add News button to add a new item. The code to create this page follows: <%@ Page Language="VB" masterpagefile="template.master" %> The code creates the following structure: http://www.apress.com The latest XML browser news. The .NET Framework includes five namespaces to implement the XML core standards. I ve only included one element in the document for brevity. The only control on the page is an AccessDataSource control: The control has the id of NewsDS, and I refer to this when creating a DataView object, as you saw earlier. The code sets the DataSourceMode to DataSet so the page can access the content programmatically in a DataView object. It also specifies the DataFile property and SelectCommand. The remainder of the application deals with managing the news content within the database.
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Web design online – 366 CHAPTER 12 CASE STUDY: USING .NET

366 CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION The next code section starts writing the XML stream, using the WriteStartDocument() method to generate the XML declaration. The WriteStartElement() method creates the root element, and sets the version attribute of this element to 2.0: XMLFeed.WriteStartDocument() XMLFeed.WriteStartElement(“rss”) XMLFeed.WriteAttributeString(“version”, “2.0″) Next, the code creates the element along with the http://www.apress.com The latest XML browser news. The code generates the remaining elements by looping through the content in the DataView. It accesses each data row in the rows collection. Each time the code finds a news item, it writes a starting element and adds the and <description> elements. The WriteElementString() method creates the opening tag, adds the specified text, and generates the closing tag: For Each dr As DataRow In dv.Table.Rows XMLFeed.WriteStartElement(“item”) XMLFeed.WriteElementString(“title”, dr(“newsTitle”).ToString()) XMLFeed.WriteElementString(“description”, dr(“newsDescription”).ToString()) XMLFeed.WriteEndElement() Next The script block finishes by writing the closing elements for each of the elements created earlier. It also calls the Flush() method to flush whatever is in the buffer to the stream, and it uses the Close() method to close the stream: <br />We would like to recommend you tested and proved <a href="http://jboss.smartwebsitehosting.net">virtual web hosting</a> services, which you will surely find to be of great quality.</p> </div><!-- .entry-content --> <footer class="entry-meta2"> </footer><!-- #entry-meta --> </article><!-- #post-447 --> <article id="post-446" class="post-446 post type-post status-publish format-standard hentry category-tomcat"> <header class="entry-header"> <h1 class="entry-title"><a href="http://www.tomcatjavahosting.com/2007/12/28/mac-os-x-web-server-chapter-12-case-study-using-net-for/" title="Permalink to Mac os x web server – CHAPTER 12 CASE STUDY: USING .NET FOR" rel="bookmark">Mac os x web server – CHAPTER 12 CASE STUDY: USING .NET FOR</a></h1> <div class="entry-meta">   <span class="author vcard" >By <a class="url fn n" href="http://www.tomcatjavahosting.com/author/admin-2/" title="View all posts by admin">admin</a> <span class="bl_sep">|</span></span> <span class="onDate"> <a href="http://www.tomcatjavahosting.com/2007/12/28/mac-os-x-web-server-chapter-12-case-study-using-net-for/" title="1:19 pm" rel="bookmark"><span class="entry-date">December 28, 2007</span> <span class="entry-time"> - 1:19 pm</span></a> <span class="bl_sep">|</span> </span> <span class="bl_categ"> <a href="http://www.tomcatjavahosting.com/category/tomcat/" title="View all posts in Tomcat" rel="tag">Tomcat</a> </span> <div class="comments-link"> <span>Comments Off</span> </div> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <p>CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION 365 XMLFeed.WriteStartElement(“item”) XMLFeed.WriteElementString(“title”, dr(“newsTitle”).ToString()) XMLFeed.WriteElementString(“description”, dr(“newsDescription”).ToString()) XMLFeed.WriteEndElement() Next XMLFeed.WriteEndElement() XMLFeed.WriteEndElement() XMLFeed.WriteEndDocument() XMLFeed.Flush() XMLFeed.Close() Response.End() End sub </script> <asp:AccessDataSource id="NewsDS" runat="server" DataSourceMode="DataSet" DataFile="App_Data/news.mdb" SelectCommand="SELECT news.newsTitle, news.newsDescription FROM news . ORDER BY news.newsTitle"/> This page doesn t use the master page, as it contains only XML content. The page starts by declaring the language and importing namespaces: <%@ Page Language="VB" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Xml" %> It then runs code in response to the page loadevent. The Page_Load subroutine starts by declaring the content type as text/xml: Sub Page_Load(Src As Object, E As EventArgs) Response.ContentType = “text/xml” The code then declares a DataView object that takes its content from the NewsDSAccessDataSource control: Dim dv As DataView = CType(NewsDS.Select(DataSourceSelectArguments.Empty), . DataView) The DataView allows the page to access the contents of the AccessDataSourcecontrol programmatically. The code uses the contents to generate the RSS feed. It starts by creating a new XmlTextWriter object: Dim XMLFeed as XmlTextWriter = new XmlTextWriter(Response.OutputStream, . Encoding.UTF8) The code sets the stream to Response.OutputStream and the encoding to UTF8. It could also specify a physical file for the XML stream. <br />We would like to recommend you tested and proved <a href="http://jboss.smartwebsitehosting.net">virtual web hosting</a> services, which you will surely find to be of great quality.</p> </div><!-- .entry-content --> <footer class="entry-meta2"> </footer><!-- #entry-meta --> </article><!-- #post-446 --> <article id="post-445" class="post-445 post type-post status-publish format-standard hentry category-tomcat"> <header class="entry-header"> <h1 class="entry-title"><a href="http://www.tomcatjavahosting.com/2007/12/28/364-chapter-12-case-study-using-net-web-server-setup/" title="Permalink to 364 CHAPTER 12 CASE STUDY: USING .NET (Web server setup)" rel="bookmark">364 CHAPTER 12 CASE STUDY: USING .NET (Web server setup)</a></h1> <div class="entry-meta">   <span class="author vcard" >By <a class="url fn n" href="http://www.tomcatjavahosting.com/author/admin-2/" title="View all posts by admin">admin</a> <span class="bl_sep">|</span></span> <span class="onDate"> <a href="http://www.tomcatjavahosting.com/2007/12/28/364-chapter-12-case-study-using-net-web-server-setup/" title="1:21 am" rel="bookmark"><span class="entry-date">December 28, 2007</span> <span class="entry-time"> - 1:21 am</span></a> <span class="bl_sep">|</span> </span> <span class="bl_categ"> <a href="http://www.tomcatjavahosting.com/category/tomcat/" title="View all posts in Tomcat" rel="tag">Tomcat</a> </span> <div class="comments-link"> <span>Comments Off</span> </div> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <p>364 CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION In this case, the code uses an XmlTextWriter object to create the XML stream and generate the content for the news feed. I didn t cover this object in Chapter 11, so Table 12-2 provides a summary of the most important methods. Table 12-2. The Most Important Methods of the XmlTextWriter Class Method Explanation WriteStartDocument() Writes the XML declaration, using version 1.0 WriteEndDocument() Closes open elements or attributes WriteComment() Writes a comment WriteProcessingInstruction() Writes a processing instruction WriteDocType() Writes the DOCTYPE declaration WriteStartElement() Writes a starting tag WriteEndElement() Closes the current tag WriteElementString() Writes an element including text WriteStartAttribute() Writes the start of an attribute WriteEndAttribute() Writes the end of an attribute WriteAttributes() Writes an attribute Flush() Flushes the buffer to the stream Close() Closes the XML stream You ll see many of these methods used in the rss.aspx page, which follows: <%@ Page Language="VB" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Xml" %> <script runat="server"> Sub Page_Load(Src As Object, E As EventArgs) Response.ContentType = "text/xml" Dim dv As DataView = CType(NewsDS.Select(DataSourceSelectArguments.Empty), . DataView) Dim XMLFeed as XmlTextWriter = new XmlTextWriter(Response.OutputStream, . Encoding.UTF8) XMLFeed.WriteStartDocument() XMLFeed.WriteStartElement("rss") XMLFeed.WriteAttributeString("version", "2.0") XMLFeed.WriteStartElement("channel") XMLFeed.WriteElementString("title", "XML Browser News") XMLFeed.WriteElementString("link", "http://www.apress.com") XMLFeed.WriteElementString("description", "The latest XML browser news.") For Each dr As DataRow In dv.Table.Rows <br />Searching for affordable and proven webhost to host and run your servlet applications? Go to <a href="http://linux.g5websitehosting.com">Linux Web Hosting</a> services and you will find it.</p> </div><!-- .entry-content --> <footer class="entry-meta2"> </footer><!-- #entry-meta --> </article><!-- #post-445 --> <article id="post-444" class="post-444 post type-post status-publish format-standard hentry category-tomcat"> <header class="entry-header"> <h1 class="entry-title"><a href="http://www.tomcatjavahosting.com/2007/12/27/web-domain-chapter-12-case-study-using-net-for/" title="Permalink to Web domain – CHAPTER 12 CASE STUDY: USING .NET FOR" rel="bookmark">Web domain – CHAPTER 12 CASE STUDY: USING .NET FOR</a></h1> <div class="entry-meta">   <span class="author vcard" >By <a class="url fn n" href="http://www.tomcatjavahosting.com/author/admin-2/" title="View all posts by admin">admin</a> <span class="bl_sep">|</span></span> <span class="onDate"> <a href="http://www.tomcatjavahosting.com/2007/12/27/web-domain-chapter-12-case-study-using-net-for/" title="1:13 pm" rel="bookmark"><span class="entry-date">December 27, 2007</span> <span class="entry-time"> - 1:13 pm</span></a> <span class="bl_sep">|</span> </span> <span class="bl_categ"> <a href="http://www.tomcatjavahosting.com/category/tomcat/" title="View all posts in Tomcat" rel="tag">Tomcat</a> </span> <div class="comments-link"> <span>Comments Off</span> </div> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <p>CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION 363 <xsl:choose> <xsl:when test="string-length(pubDate)>0″> <strong>Published: </strong><xsl:value-of select="pubDate"/> </xsl:when> </xsl:choose> </div> <p> </xsl:template> </xsl:stylesheet> Again, the test uses the XPath string-length function to test the length of the <pubDate> element. If the element exists, the publish date is included in the XHTML output. Notice that the stylesheet doesn t contain an <xsl:otherwise>element here so that nothing displays if no publish date exists. The stylesheet is first applied to the rss.aspx news feed when the home page initially loads. rss.aspx When users view the home page for the first time, it displays the default local RSS feed from the page rss.aspx. Users can also view this feed by clicking the RSS 2.0 image button. They can reference the rss.aspx page directly to consume the feed. If you click the RSS 2.0 button, you should see something similar to the image shown in Figure 12-4. Figure 12-4. The RSS feed shown in Internet Explorer (IE) <br />Searching for affordable and proven webhost to host and run your servlet applications? Go to <a href="http://linux.g5websitehosting.com">Linux Web Hosting</a> services and you will find it.</p> </div><!-- .entry-content --> <footer class="entry-meta2"> </footer><!-- #entry-meta --> </article><!-- #post-444 --> <article id="post-443" class="post-443 post type-post status-publish format-standard hentry category-tomcat"> <header class="entry-header"> <h1 class="entry-title"><a href="http://www.tomcatjavahosting.com/2007/12/27/362-chapter-12-case-study-web-hosting-control-panel-using-net/" title="Permalink to 362 CHAPTER 12 CASE STUDY: (Web hosting control panel) USING .NET" rel="bookmark">362 CHAPTER 12 CASE STUDY: (Web hosting control panel) USING .NET</a></h1> <div class="entry-meta">   <span class="author vcard" >By <a class="url fn n" href="http://www.tomcatjavahosting.com/author/admin-2/" title="View all posts by admin">admin</a> <span class="bl_sep">|</span></span> <span class="onDate"> <a href="http://www.tomcatjavahosting.com/2007/12/27/362-chapter-12-case-study-web-hosting-control-panel-using-net/" title="3:13 am" rel="bookmark"><span class="entry-date">December 27, 2007</span> <span class="entry-time"> - 3:13 am</span></a> <span class="bl_sep">|</span> </span> <span class="bl_categ"> <a href="http://www.tomcatjavahosting.com/category/tomcat/" title="View all posts in Tomcat" rel="tag">Tomcat</a> </span> <div class="comments-link"> <span>Comments Off</span> </div> </div><!-- .entry-meta --> </header><!-- .entry-header --> <div class="entry-content"> <p>362 CHAPTER 12 CASE STUDY: USING .NET FOR AN XML APPLICATION The stylesheet then matches the document element and applies the template for the <channel> element: <xsl:template match="/"> <xsl:apply-templates select="rss/channel"/> </xsl:template> The <channel> element template creates the heading information: <xsl:template match="channel"><br /> <h2><a href="{link}" target="_blank"><xsl:value-of select="title"/></a></h2> <p> <xsl:apply-templates select="item"/> </xsl:template> Here, the stylesheet creates a link around the <title> element so that the user can access it in a new browser window. The stylesheet displays this as a level 2 heading and places the transformation from the <item> elements underneath. The final template matches each <item> element. It checks to see if the XML document contains a <link> element. If so, the <title> element displays as a hyperlink to the relevant URL; otherwise, it appears as an<br /> <h3> element: <xsl:template match="item"><br /> <h3> <xsl:choose> <xsl:when test="string-length(link)>0″> <a href="{link}" target="_blank"><xsl:value-of select="title"/></a> </xsl:when> <xsl:otherwise> <xsl:value-of select="title"/> </xsl:otherwise> </xsl:choose> </h3> <p> Notice that the stylesheet uses <xsl:when> and <xsl:otherwise> to add conditional logic. The built-in XPath function string-length tests the length of the text within the <title>element. If the length is greater than 0, the heading is linked. Once the stylesheet writes the news item heading, it displays the item content in a <div> element: <div class="indent"> <xsl:value-of disable-output-escaping="yes" select="description"/><br/> The value of disable-output-escaping is set to yes so that the stylesheet doesn t escape any XHTML tags in the <description> element. As you ll see from some of the news feeds, it s common to add XHTML content in the description. The stylesheet includes another logical test, this time looking to see if a publish date exists: <br />In case you need quality webspace to host and run your web applications, try our <a href="http://j2ee.g5websitehosting.com">personal web hosting</a> services.</p> </div><!-- .entry-content --> <footer class="entry-meta2"> </footer><!-- #entry-meta --> </article><!-- #post-443 --> <nav class='pagination'><span class='current'>1</span><a href='http://www.tomcatjavahosting.com/2007/12/page/2/' class='inactive' >2</a><a href='http://www.tomcatjavahosting.com/2007/12/page/3/' class='inactive' >3</a><a href='http://www.tomcatjavahosting.com/2007/12/page/2/'>›</a><a href='http://www.tomcatjavahosting.com/2007/12/page/7/'>»</a></nav> </div><!-- #content --> <div id="primary" class="widget-area" role="complementary"> <ul class="xoxo"> <li id="search-2" class="widget-container widget_search"> <form method="get" id="searchform" action="http://www.tomcatjavahosting.com//"> <input type="text" value="Search" name="s" id="s" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search') {this.value = '';}" /> <input type="submit" id="searchsubmit" value="OK" /> </form></li> <li id="recent-posts-2" class="widget-container widget_recent_entries"> <h3 class="widget-title">Recent Posts</h3> <ul> <li> <a href="http://www.tomcatjavahosting.com/2012/08/17/j-rn-zaefferer-is-a-professional-software-developer-from/">J rn Zaefferer is a professional software developer from</a> </li> <li> <a href="http://www.tomcatjavahosting.com/2012/08/16/about-the-reviewers-marc-grabanski-got-involved-early/">About the Reviewers Marc Grabanski got involved early</a> </li> <li> <a href="http://www.tomcatjavahosting.com/2012/08/15/about-the-author-dan-wellman-lives-with-his/">About the Author Dan Wellman lives with his</a> </li> <li> <a href="http://www.tomcatjavahosting.com/2012/08/14/credits-author-dan-wellman-reviewers-marc-grabanski-akash/">Credits Author Dan Wellman Reviewers Marc Grabanski Akash</a> </li> <li> <a href="http://www.tomcatjavahosting.com/2012/08/13/jquery-ui-1-7-the-user-interface-library-for-2/">jQuery UI 1.7 The User Interface Library for</a> </li> </ul> </li><li id="archives-2" class="widget-container widget_archive"><h3 class="widget-title">Archives</h3> <ul> <li><a href='http://www.tomcatjavahosting.com/2012/08/'>August 2012</a></li> <li><a href='http://www.tomcatjavahosting.com/2008/01/'>January 2008</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/12/'>December 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/11/'>November 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/10/'>October 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/09/'>September 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/08/'>August 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/07/'>July 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/05/'>May 2007</a></li> <li><a href='http://www.tomcatjavahosting.com/2007/04/'>April 2007</a></li> </ul> </li><li id="linkcat-2" class="widget-container widget_links"><h3 class="widget-title">Blogroll</h3> <ul class='xoxo blogroll'> <li><a href="http://www.astrawebhosting.net/blog/">Adult Web Hosting</a></li> <li><a href="http://apache.tomcatjavahosting.com">Apache Web Hosting</a></li> <li><a href="http://jsp.tomcatjavahosting.com">Christian Web Host</a></li> <li><a href="http://coldfusion.tomcatjavahosting.com">Coldfusion Web Hosting</a></li> <li><a href="http://www.visionwebhosting.net/blog/">Database Web Hosting</a></li> <li><a href="http://www.virtualwebstudio.com/blog/">Dedicated Web Hosting</a></li> <li><a href="http://domain.g5websitehosting.com">Domain Name Hosting</a></li> <li><a href="http://jboss.tomcatjavahosting.com">Ecommerce Web Host</a></li> <li><a href="http://www.gamahosting.net/blog/">Frontpage Web Hosting</a></li> <li><a href="http://domain.smartwebsitehosting.net">Ftp Web Hosting</a></li> <li><a href="http://mysql5.tomcatjavahosting.com">Http Web Server</a></li> <li><a href="http://www.g5websitehosting.com">Inexpensive Web Hosting</a></li> <li><a href="http://j2ee.tomcatjavahosting.com">J2ee Web Hosting</a></li> <li><a href="http://www.visionwebhosting.net">Java hosting</a></li> <li><a href="http://tomcat.smartwebsitehosting.net">Java Server Pages</a></li> <li><a href="http://www.tomcatjavahosting.com">Java Web Hosting</a></li> <li><a href="http://www.smartwebsitehosting.net">Java Web Server</a></li> <li><a href="http://php5.g5websitehosting.com">Jboss Hosting</a></li> <li><a href="http://linux.g5websitehosting.com">Linux Web Hosting</a></li> <li><a href="http://mysql.g5websitehosting.com">MySQL Web Server</a></li> <li><a href="http://tomcat.g5websitehosting.com">MySQL5 Web Hosting</a></li> <li><a href="http://www.worldmythology.ws">Mythology</a></li> <li><a href="http://j2ee.g5websitehosting.com">Personal Web Hosting</a></li> <li><a href="http://www.omnicus.net/">Personal Web Server Hosting</a></li> <li><a href="http://php5.tomcatjavahosting.com">PHP5 Hosting</a></li> <li><a href="http://www.cheap-web-hosting-reviews.net">PHP5 Web Hosting</a></li> <li><a href="http://php5.smartwebsitehosting.net">Professional Web Hosting</a></li> <li><a href="http://mysql5.smartwebsitehosting.net">Servlet Web Hosting</a></li> <li><a href="http://j2ee.smartwebsitehosting.net">Shared Web Hosting</a></li> <li><a href="http://domain.tomcatjavahosting.com">Tomcat Web Hosting</a></li> <li><a href="http://jboss.smartwebsitehosting.net">Virtual Web Hosting</a></li> <li><a href="http://www.superbvpn.com">Vpn</a></li> <li><a href="http://www.supervpn.net">Vpn services</a></li> <li><a href="http://www.supervpshosting.net">Vps hosting</a></li> <li><a href="http://coldfusion.smartwebsitehosting.net">Web And Email Hosting</a></li> <li><a href="http://mysql5.g5websitehosting.com">Web Design Programs</a></li> <li><a href="http://www.webhostingjava.net/">Web Hosting Mysql5</a></li> <li><a href="http://www.webhostingphp.net/">Web Hosting Plans</a></li> <li><a href="http://www.actionswebhosting.com/blog/">Web Hosting Services</a></li> <li><a href="http://www.sandzak.com/blog/">Web Server Hosting</a></li> <li><a href="http://www.alphawebhosting.net/blog/">Web Site Optimization Hosting</a></li> </ul> </li> </ul> <ul class="xoxo"> </ul> </div><!-- #primary .widget-area --> <!-- 1c --> </section><!-- #primary --> <div style="clear:both;"></div> </div> <!-- #forbottom --> </div><!-- #main --> <footer id="footer" role="contentinfo"> <div id="colophon"> </div><!-- #colophon --> <div id="footer2"> <div id="site-info" > <a href="http://www.tomcatjavahosting.com/" title="Java Web Hosting, Subdomain, Vps Hosting, Cpanel, Programming Blog" rel="home">Java Web Hosting, Subdomain, Vps Hosting, Cpanel, Programming Blog</a> | <b title="1.9.7">Mantra</b> Theme by <a href="http://www.riotreactions.com" title="Visit author homepage">Cryout Creations</a> | Powered by <a href="http://wordpress.org/" title="Semantic Personal Publishing Platform"> WordPress. </a> </div><!-- #site-info --> </div><!-- #footer2 --> </footer><!-- #footer --> </div><!-- #wrapper --> </body> </html>