|
|
|
|
|
|
|
Total page views :
9345
|
|
Total downloads :
|
|
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
|
|
|
|
|
|
|
|
Your XML document is a well-organized container of information, but it seems static.Although the document format is useful in representing information structurally, you still tied down to software applications specifically made to handle it.
What if you want to see the document in an HTML browser that doesn't support XML? Or output it as text for printing.
You see how an XML application can replace a word processor or a browser. This is advantageous because you can begin with an XML document (which can be read from a database, a file in your local system, or downloaded from the Web) and transform it through a style sheet by processor, (or manipulated through the myriad of XML tools available to us) yielding another document (possible another filtered XML document). The XML solution is then to separate authoring from publishing therefore the author of the pages writes the document in XML, thinking in a well-formed and logic structure adopting an XML vocabulary that focuses on the organization of the document, and not handle the presentation in terms of sections, titles, abstracts and more.
So publishing the document then simply requires converting the document into HTML, WML, or another popular format.
There are three main roles:
1. The documents in structure-rich XML providing the static information.
2. XLST style sheets that implements the conversion to HTML, WML or another format. This is a scripting language optimized for conversion of XML documents.
3. An XSLT processor that is responsible for applying the style sheets and generating an output format, which options might be:
- HTML: is not an XML vocabulary. There is no XML to XML transformation, but HTML is used by Web browser to display information.
- XHTML: an XML application of HTML. The major advantage is that it is based on HTML so it will be familiar for Web designers. Currently it is too complex for mobile phones. W3C is working to simplify XHTML.
- ML: the markup language for WAP devices. It is an XML application used for wireless applications, such as mobile phones. You can think of WML as an HTML for mobile users.
- OpenBook: the format for eBook, based on HTML. Another interesting format for mobile users designed for eBook, a different groups a mobile user. An eBook can take a lot of forms, but it is generally a palm-size device on which readers download books.
- XSLFO: a new display language that is optimized for printed documents.
For more information about XSLT, there is an XSLT specification on the Web; you can rich it at www.w3.org/TR/xslt.
This paper shows how we can take advantage of the former ideas, using the technologies shipped in Microsoft.NET platform.
Suppose you have a bookstore and you want to publish all the books for sale. For this solution, I'll use ASP.NET over Microsoft.NET as the Web environment.
First of all you have to analyze and design your solution, so define the items (objects holding information) to publish, and the attributes of such items, in this case: the title, author, an abstract according the theme exposed, and a collection of paragraphs.
Figure 1 shows an XML document with all the information of my bookstore. You may notice how the items are represented in this document in a logic manner, expressing the containment of objects, so the parent-child relationship.
<? xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="BookFair.xslt"?> <News> <URL>http://www.john.com</URL> <Item> <Title>Using XML.</Title> <Author>Author1</Author> <Abstract> A new intermediate/advanced book for XML developers. </Abstract> <Para> Learn advanced XML programming with Applied XMLSolutions. This hands-on teaching book is filled with practical examples. </Para> <Para> Applied XML Solutions is a great complement to XML by Example. </Para> <Para> This is the end paragraph. </Para></Item> <Item> <Title>XML programming</Title> <Author>Author2</Author> <Abstract> XML for novice. </Abstract> <Para> This is a book for novice in XML as Web technologies. </Para> </Item> <Item> <Title>.NET Programming</Title> <Author>Author3</Author> <Abstract> About everything in .NET platform. </Abstract> <Para> A book that explains how you can use Microsoft.NET for your Web Solutions.</Para> <Para> The best book about Microsoft.NET. </Para> </Item> <Item> <Title>Windows Programming</Title> <Author>Author4</Author> <Abstract> How to use Windows API. </Abstract> <Para> A very instructive book about how to program to Win32. </Para> <Para> You can learn to use the Windows API. </Para> </Item> </News>
Figure 1.(BookFair.xml).
I then define the transformation rules to generate an HTML table for showing to the Web customers. In figure 2, you can see the XSL rules.
<? xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform>" <xsl:template match="News"> <h1>Show items of my company.</h1> <table width="735" height="130" border="1"> <caption> Books Information. </caption> <tr> <th width="33" scope="col">Pos</th> <th width="162" scope="col">Author</th> <th width="169" scope="col">Title</th> <th width="343" scope="col">Param</th> </tr> <xsl:for-each select="Item"> <tr> <td><xsl:value-of select="position()"/></td> <td> <b> <xsl:value-of select="Author"/> </b> </td> <td> <p> <xsl:value-of select="Title"/> </p> </td> <td> <xsl:apply-templates select="Para"/> </td> </tr> </xsl:for-each> </table> </xsl:template> <xsl:template match="Para"> <p><xsl:apply-templates/></p> </xsl:template> </xsl:stylesheet>
Figure 2. (BookFair.xlst).
The Web application that processes the documents is composed by page named BookFair.aspx (figure 3) as the view of the application, and a file hosting all the objects that implements the logic of the application it is named BookFair.aspx.cs (figure 4).
<%@ Page language="c#" Codebehind="BookFair.aspx.cs" AutoEventWireup="false" Inherits="BookFair.BookFairForm" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5>" </HEAD> <body MS_POSITIONING="GridLayout"> <h1>John Olamendy Test.</h1> <p> <%Response.Write(m_strXmlOutput);%> </p> </body> </HTML>
Figure 3.( (BookFair.aspx)
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; using System.Xml.Xsl; using System.IO; namespace BookFair { public class BookFairForm : System.Web.UI.Page { protected string m_strXmlOutput; private void Page_Load(object sender,System.EventArgs e) { //This is the logic of the application. XslTransform objTransform=new XslTransform(); XmlDocument objDocument=new XmlDocument(); string strAppPath=this.Server.MapPath(""); StringWriter objStream=new StringWriter(); objDocument.Load(strAppPath+\\BookFair.xml); objTransform.Load(strAppPath+\\BookFair.xslt); objTransform.Transform(objDocument,null,objStream,null); this.m_strXmlOutput=objStream.ToString(); } override protected void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } } }
Figure 4. (BookFair.aspx.cs)
And as you can see this is an application for Web. But in the same manner it is possible create an application for Mobile Users, only changing the view side, and maintaining the documents. This is a good practice of design named model-view, where you have the logic of your application and this logic can be applied for any view no matter if it is a desktop application, a Web application or Wireless application.
Eng. John Charles Olamendy Turruellas.
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
|
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
|
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or
application via a range of API's. Learn More about our API connections.
|
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|