The current time is It never changes since the page is cached
At the top of the page, the OutputCache directive is used to cache the contents of the page in memory The duration attribute of the OutputCache directive is set to 6000 seconds The VaryByParam attribute indicates whether or not ASP.NET should consider the parameters passed to the page when caching When VaryByParam is set to none, no parameters will be considered; all users receive the same page no matter what additional parameters are supplied The MethodName attribute of the Substitution control is set to a method named GetRandomNumber, which simply returns a random number between and 10000 Note that the return value of GetRandomNumber method is string because the HttpResponseSubstitutionCallback delegate always requires a return type of string When you make a request for the page through the browser, you will find that the displayed current time always remains the same whereas the portion of the page that is generated by the substitution control keeps changing every time In this case, it displays a random number between and 10000 every time someone requests the page 39 Chapter Summar y This chapter provided you with a quick tour of the features of ASP.NET 2.0 Specifically, this chapter discussed the number of new productivity enhancements of ASP.NET 2.0 that are exciting for the developers In addition, this chapter also discussed the configuration and management of ASP.NET Web applications as well as the performance improvement features Apart from the features discussed so far, ASP.NET 2.0 provides the following features ❑ ❑ ASP.NET 2.0 will be almost completely backward compatible with ASP.NET 1.0 and ASP.NET 1.1 ❑ You can also define a single class in multiple files and at runtime will be compiled together to create a single assembly ❑ With ASP.NET 2.0, you can perform postback across pages, meaning that you can postback to another page from one page To perform cross-postback when the user clicks a button, set the PostTargetUrl property on the button control to the URL of the new page From within the new page, you can reference the original page using the PreviousPage property ❑ 40 ASP.NET 2.0 is 64-bit enabled In the health monitoring space, it provides support for automated notification when exceptions occur in the Web site For example, ASP.NET can automatically send an email to the admin when an exception occurs in the Web site XML Classes in the NET Framework The first two chapters provided you with an introduction to XML and ASP.NET 2.0, respectively In this chapter, you get an understanding of the XML support in the NET Framework The initial release of NET Framework provided excellent support for working with XML in NET applications The NET Framework 2.0 builds on the foundation of NET 1.x by providing new classes and features such as better standards support, increased performance improvements, and so on In addition, XML core classes are tightly integrated with key areas of the NET Framework, including data access, serialization, and applications configuration This chapter discusses the overall support for XML in the NET Framework Specifically, this chapter focuses on the XML classes in the NET Framework that provide support for standards such as XML 1.0, XML namespaces, Document Object Model (DOM) Level Core, XML Schema Definition (XSD) Language, Extensible Stylesheet Language Transformations (XSLT), and XPath expressions XML Suppor t in the NET Framework 2.0 Microsoft is serious about NET’s commitment to XML This is made obvious by the extent to which XML is used in the NET architecture and supported through several feature-rich namespaces In this chapter, you are introduced to the XML API in the NET Framework Before looking at the XML support in the NET Framework, it is important to examine the design goals of NET Framework 2.0 Design Goals for XML Support in NET Framework 2.0 Through the XML namespaces and classes present in the NET Framework 2.0 base class library, you can easily build XML support into your applications These classes enable you to read, write, manipulate, and transform XML Because XML manipulation is inevitable in application development, it is recommended that all developers have an understanding of these core XML classes When the XML team in Microsoft started designing the XML feature set for the NET Framework 2.0, they had the following design goals in mind: Chapter ❑ Better Standards compliance — Support for the major W3C XML standards that provide crossplatform interoperability, such as XML 1.0, XML Namespaces 1.0, XSLT 1.0, XPath 1.0, and W3C XML schema 1.0 ❑ Usability — XML API should be not only easy-to-use but also intuitive ❑ Seamless Integration with ADO.NET — The classes in the XML API can really be considered part of ADO.NET as an XML data access API The combination of System.Data.DataSet and the System.Xml.XmlDataDocument classes provide a seamless experience when moving between XML and relational data ❑ Significant Performance Improvements — This was the number one requirement for the NET Framework 2.0 release The new XSLT processor through the introduction of the new System Xml.Xsl.XslCompiledTransform class is one of the many performance improvements with XML API in NET Framework 2.0 ❑ Developer Productivity enhancements — These enhancements are geared towards increasing the productivity of the developers by allowing them to perform common tasks even easier to in less lines of code ❑ Support for Strong Types and XML schema — In the NET Framework 1.x, almost all of the XML API were untyped in that the data was both stored and retrieved as string types This is enhanced in NET Framework 2.0 by integrating schema information deeply across the XML namespaces This provides for more efficient storage, improved performance, and better integration with the NET programming languages XML Namespaces XML API in NET Framework 2.0 is mainly encapsulated in five namespaces These namespaces house all of the XML functionality within the NET Framework class library Table 3-1 describes these namespaces at a high level Table 3-1 XML Namespaces in NET Framework 2.0 Namespace Description System.Xml Contains the classes that provide the core of all XML functionality System.Xml.Schema Provides support for XML Schema Definition Language (XSD) schemas System.Xml.Serialization Provides classes that allow you to serialize and deserialize objects into XML formatted documents System.Xml.XPath Provides support for the XPath parser and evaluation functionality System.Xml.Xsl Provides support for XSLT transformations The next few sections provide an overview of the classes and functionalities contained in these namespaces 42 XML Classes in the NET Framework The System.Xml Namespace The classes in the System.Xml namespace are designed to fully support your XML needs Your needs may range from reading and writing XML to storing XML In fact, your application’s needs may even extend to querying XML or transforming XML There are many feature-rich classes available in this namespace that provide reading, writing, and manipulating XML documents The System.Xml.Schema Namespace This namespace offers classes, delegates, and enumerations used to support your XSD language needs It strongly supports the W3C Recommendations for XML schemas for structures and XML schemas for data types The classes in this namespace service the Schema Object Model (SOM) The System.Xml.XPath Namespace This namespace offers support for the XPath parser (query support) via several classes, interfaces, and enumerations Two commonly used classes from this namespace are XPathDocument (fast, read-only cache, optimized for XSLT) and XPathNavigator (editable, random access, cursor model) Note that the XPathNavigator class can now be used to edit XML data in addition to providing a cursor model for navigating XML data The System.Xml.Xsl Namespace This namespace provides full support for the Extensible Stylesheet Transformation (XSLT) technology Although several classes and interfaces are offered in this namespace, you will likely use the XslCompiledTransform class and XsltArgumentList classes most often The System.Xml.Serialization Namespace This namespace offers classes and delegates to assist with object serialization Among the many managed classes offered, you will use the XmlSerializer class the most Using the XmlSerializer class, you can serialize and deserialize instantiated objects to and from XML documents or streams Object serialization is a useful technique for persisting (or saving) the state of an object so that you can later re-create an exact copy of the object Object serialization is also useful when you want to pass the object (marshal by value) during NET Remoting scenarios The preceding list of namespaces is provided to give you a more complete picture of the XML support available through the NET Framework and platform Combining this information with that of the classes in the System.Xml namespace, you are certainly off to an informed start Now that you have understood the different XML namespaces, you are ready to examine the different XML-related capabilities such as XML Parsing, XML Validation, XPath, XML Serialization, XML Web Services, and so on, and how they are supported in NET Framework 2.0 The next section examines how XML is enabled in NET Framework XML Parsing Parsing is not always as simple as just reading through an XML document and verifying it for ASCII text The structure and rules of your governing DTD, or XSD schemas can be verified when processing these instance documents if you utilize a validating parser You need this parsing application to evaluate the instance document and determine if it’s valid and then make it available for secondary applications to utilize the data contained therein 43 Reading and Writing XML Data Using XmlReader and XmlWriter if(reader.Name == “employee”) { employeeID = reader.GetAttribute(“id”); } During the next pass, the script encounters the other parameters associated with a particular employee such as firstName, lastName, city, state, and zipCode For each of these elements except for the zipCode element, the ReadString() method can be used to retrieve the text stored in the corresponding element if(reader.Name==”zipCode”) { lblResult.Text += “