Using AUTO Mode
If we use FOR XML AUTO, the resultant XML not only maps column names to attributes as in RAW mode , but it also maps the table names to the XML element names. This is handy when we want to see the hierarchical nature of a JOIN in a SELECT statement. Consider the following SQL statement, which joins the Categories table to the Products table SELECT Category . CategorylD , Category . CategoryName , Product . ProductID , Product . ProductName FROM Categories AS Category INNER JOIN Products AS...
The BasketService
The BasketService provides the functionality to select, edit, and maintain a list of items with methods that are pretty much as you would see in a traditional e-commerce web site although, as we've said previously, in a very simplified manner . The basket details are all held in a single column, BasketDetails, as an XmlDocument, so any actions on an item are all preformed by retrieving this column, moving it to an XmlDocument, manipulating the document, and then storing it back in the table....
A Sample ASP NET Project using XQuery
Let's see how XQuery could be used in an ASP.NET project by creating an application to retrieve the current orders of any customer in the SQL Server Northwind sample database, and display the customer's details together with some order details. This project uses SQLXML and SQL Server 2000 to set up a virtual XML database, and then runs XQueries over the selected customer. The results are in XML format, so we'll use XSLT to present them on the user's screen. Note that although XQuery will...
Info Srw
Note particularly that the absence of an axis implies child, node , appearing in the above examples, returns true for all nodes at the current location, and we'll cover it further in the section headed The Node-Test, once we've looked at some examples of these five axes used with our sample XML file. The following expression retrieves the lt customer gt element using an absolute location path customer The more readable abbreviated form would be
The DisplayEmployeesaspx Web Form
Add a new Web Form to our SQL2000 web application, and name it DisplayEmployees . aspx. Using HTML view, remove all markup so that only the Page directive remains lt Page language c AutoEventWireup false Inherits gt In the previous chapter, we used an XSLT style sheet named EmployeeTransf orm. xslt in one of our examples, and will come in useful in this project too. Add it as an existing item, placing it in the project folder. In the code file, DisplayEmployees.aspx.es, add the code highlighted...
Info Sdu
While XmlValidatingReader implements the XmlReader class, we don't always start with an X 1T document and associate a validating reader with it. More commonly, we already have an XmlTextReader attached to an XML file as in the preceding example , and then attach it to a validating reader to perform validation functions. This reflects the fact that XmlValidatingReacJ a layer of validation functionality over and above the core, stream-based model, and allows us to wri programs in which we decide...
Info Grm
Now add the element as a child of the DocumentElement objXmlDocument . DocumentElement . AppendChild objXmlElement XslTransform objXslTransform new XslTransform XPathNavigator objXPathNavigator ob j XmlDocument .CreateNavigator objXslTransform. Load Server .MapPath createSearchlnf o.xslt XmlReader objXmlReader objXslTransform. Transform XmlDocument objXmlDocument2 new XmlDocument objXmlDocument2 .Load objXmlReader return obj XmlDocument 2 Our final method is getHierarchy. This returns an...
Info Szx
The first change above captures a possible value named category from the query-string. Our next change is the declaration of a new Xs It Argument List object. We initialize it to null, and only instantiate it if there is a value in the _Param string. If there is a value, we instantiate the object and call the AddParam method to set the value of the _Param string as the CategoryParam named parameter in the XSLT style sheet. The middle argument in AddParam is for namespace support. If we now save...
Info Xiw
Retrieves the BasketDetail column from the appropriate row and loads the value into an XmlDocument. The Item is located and the element removed. The itemCount attribute is updated before the XML is stored back into the database table. Retrieves the BasketDetail column from the appropriate row and loads the value into an XmlDocument. The Item is located - if the new quantity is 0 then the element is removed, otherwise the old quantity is overwritten with the new quantity. We won't go through the...
WSSecurity and WSLicense
The purpose of this specification is to provide a set of SOAP extensions that can be used separately or together to build secure Web Services by enabling the passing of security information credentials , the use of XML-Signa'ure to ensure message integrity, and the use of XML-Encryption for message confidentiality. Organizations use credentials to positively identify each other before they start transacting. WS-Security can be used to exchange many different types of credentials, providing a...
Info Edj
lt table style border thick solid gt lt tr s tyle background- color 00 00 00, -color FFFFFF gt lt th gt Line Number lt th gt lt th gt Item Number lt th gt lt th gt Description lt th gt lt th gt Quantity lt th gt lt th gt List Price lt th gt lt th gt Notes lt th gt lt tr gt lt xsl f or-each select item gt lt xsl sort select list-price data- type ' number ' order ' descending gt lt xsl element name tr gt lt xsl attribute name M style M gt lt xsl choose gt lt xsl when test position mod 2 gt...
Info Avt
data-type MnumberM order MdescendingM gt lt xsl apply-templates gt lt hl gt Item Product Lines lt hl gt lt xsl apply-templates select M itemn mode MPLM gt lt xslrsort select M8idM data-type MtextM order MdescendingM gt lt xsl apply-templates gt lt body gt lt html gt lt xsl template gt Notice how we've changed both lt apply-templates gt elements so that they are no longer empty. Each now has a lt sort gt child element, with attributes specifying how to perform the sort. In our example, the...
A Word about XmlLinkedNode
If you refer back to the inheritance hierarchy we presented at the beginning of this chapter, you'll find a number of classes derived from XmlLinkedNode. They include classes for all of the XML constructs other than attributes, entities, and notations. What's significant about XmlLinkedNode classes is that they represent the XML types for which node order is important. In consequence, XmlLinkedNode overloads those properties of XmlNode that are important to ordered traversal, namely NextSibling...
properties Nuf
Attributes read-only HasAttributes read-only InnerXml read write IsEmpty read write LocalName read-only Name read-only NamespaceURl read-only NodeType read-only OwnerDocument read-only Prefix read write Returns an XmlAttributeCollection containing all of the attributes of this element. Returns true if the element has attributes, or false otherwise. This property is an extension to the DOM. Gets or sets the concatenated text nodes of the element and any children. If set, the children of this...
Using SOAP over EMail
As previously mentioned, SOAP is not tied exclusively to HTTP but is designed to work with any transport protocol. One obvious alternative to HTTP is the mail protocol SMTP. Sending our credit check request over SMTP may look something like this although SOAP does not actually specify any bindings, that is what needs to appear in an e-mail header and body, for SMTP From online.application theloancompany.com To creditcheck checkcredit.com Subject Individual Credit Check Date Fri, 1 Dec 2002 10...
Building a SOAP Test Harness
Building a simple SOAP-based application to test our services can easily be done in an Internet Explorer HTML page. In the code download, testHarness2 .htm, gives us a suitable test harness and has the following appearance I WOAP Tetter Microsoft Internet Explorer Rte lt St View Favorites Tods Help ' Address lt xml version 1.0 encoding utf-8 gt lt soap Envelope xmlns xsi http www. w3.org 2001 XMLSchema-instance xmlns xsd http www. w3.org 2001 XMLSchema xmlns soap http schemas. xmlsoap.org soap...
XmlReader and XmlWriter
Having read through the previous chapter, you're probably eager to start applying some of your XML know-how to XML documents in ASP.NET. In order to do that, you need to understand how to move documents back and forth, how to read them, how to parse them, and how to create them programmatically. In this chapter, we're going to see a series of .NET Framework classes that provide all these abilities, observing the rules of well-formed XML markup as they go. Specifically, this chapter will cover Q...
Info Tfx
Now simply click the SelectSingleNode button, using the same XPath expression. This is the new result Prefix for Default Namespace C XPath Expression Awx item Context Node item, Node Type Element lt item id ITM-1001 productl_ine l xmlns urn wrox-asp.net-xml- The MessageLabel indicates the context node is now the first lt item gt element in the document. We can see that using an XPath expression which renders multiple nodes will return only the first matching node when executed with...
Creating the XQueryNavigatorCollection Object
Everything's now ready for us to begin writing some C code, starting with the code-behind page, Global. asax. cs. Add the following namespace declarations at the top of the file, just before the namespace XQuerySearchEngine line Then, add the following variable declarations just after the public class Global declaration Declare variables string strUrlXmlTemplateCustomers string strTJrlXmlTemplateOrders string strUrlXmlTemplateOrderDetails string strUrlXmlTemplateProducts string...
Differences between SOAP 11 and SOAP 12
At the time of writing, SOAP 1.2 is in Working Draft. ASP.NET's Web Service support is 1.1 compliant and WSDL binds to 1.1 but for completeness we will have a look the current major differences between SOAP 1.1 and SOAP 1.2 in addition to the different namespace of course Q SOAP 1.2 does not permit any element after the body. G SOAP 1.2 defines the new lt Misunderstood gt header element for conveying information on a mandatory header block that could not be processed. 3 SOAP 1.2 provides two...
Using XsltArgumentList to Add Parameters
We have to return to Visual Studio .NET, and modify our TransformXML.aspx.es code to provide support for parameters. We will use the XsltArgumentList object, which we then pass to the Transform method of the XslTransf orm object. Make the following changes to our Page_Load event handler private void Page_Load object sender, System. Even tArgs Put user code to initialize the page here string XMLPath Request . QueryString xml m string _XSLTPath Request .QueryString xslt string Param Request...
