[ Pobierz całość w formacie PDF ]
.NoteIf a com plex element nam e in a schem a matches a rowsource name in a database, you don t need to designate thecorrespondence between the two with the relation attribute.The following annotated schem a dem onstrates the use of the relation and fieldattributes.The schem a form ats an XML docum ent with a com plex elem ent typenam ed xm lShippers that has two child elem ents, xm lCom panyNam e andxm lPhone, and an attribute, ShipperI D.Notice that the relation and fieldattributes appear with a sql prefix to specify the nam espace for defining theattributes.The sql: relation attribute points the xm lShippers elem ent to theShippers row source.The sql: field attributes for the xm lCom panyNam e and xm lPhone elem ents link these elem ents to the Com panyNam e and Phone colum nsin the Shippers row source.Because the ShipperI D attribute nam e m atches acolum n in the Shippers row source, it doesn t require a sql: field attribute settingto link it to a colum n within the row source.With three m ore steps, you can return an XML docum ent based on the Shippersrow source.1.Save the annotated schem a in a virtual directory configured to connect tothe Northwind database.Because the Northwind table contains a tablenam ed Shippers, this defines the row source in the annotated schem a.2.Create a new XML docum ent, called a tem plate, that invokes theannotated schem a.By invoking the query with XPath syntax, the tem platefile can cause the annotated schem a to return a view of the Shippers tableas an XML docum ent.3.Navigate to the tem plate from a browser to return the view specified bythe tem plate to the browser s docum ent window.The following XML docum ent illustrates the syntax for referring to the precedingannotated schem a in xm lShippersSchem a.xm l.The specification requires theschem a to reside in a special tem plate folder within the virtual directory, but youcan explicitly designate another source for the annotated schem a file.The actualquery syntax sim ply references the elem ent with the sql: relation attribute setting,nam ely xm lShippers.This form of an XPath query requests the return of all therows from the Shippers table.The XPath query is equivalent to SELECT * FROMShippers in T-SQL./xmlShippersThe top screen shot in Figure 6-2 shows the Shippers table in XML form at basedon the annotated schem a in xm lShippersSchem a.xm l and the tem plate file(xm lShippersSchem aT.xm l) that queries the schem a.The browser s Address boxshows the path to the tem plate file that contains the XPath query.The tem plateresides on an I I S server nam ed ccs1.The tem plate is in the tem plate folder of theMyNwind virtual directory.The use of the nam e tem plate for the tem plate folderis arbitrary.Any other nam e will serve equally well.The XML docum ent in thebrowser window follows the form at of the annotated schem a.Notice that ShipperI D appears as an attribute, but xm lCom panyNam e and xm lPhone appearas elem ents.Whereas the data values are from the Shippers table in theNorthwind database, the elem ent and attribute nam es are from the annotatedschem a.Figure 6 - 2.A pair of screen shots illustrating different result sets fromthe sam e annotated schem a based on tw o tem plates w ith different XPathqueries.The lower screen shot in Figure 6-2 shows the result of an XPath query that asksfor the return of just the row with ShipperI D equal to 3.The syntax for thetem plate with the query appears below.The param eter for ShipperI D has aleading @.Notice that the Address box points to the file with the followingtem plate.By contrasting the following tem plate with the preceding one, you cansee how to reuse an annotated schem a to derive different result sets.I n a sense,the annotated schem a serves as a param eterized view! /xmlShippers[@ShipperID=3]Recall that annotated schem as sim ulate views in SQL Server databases.Becauseviews often join tables, the next annotated schem a m erges the Orders table withthe Shippers table to m ake available the orders by ShipperI D.The schem a has tospecify the join between the tables in the original SQL Server data source.Theschem a specifies the join with a relationship elem ent (not to be confused with arelation elem ent).The relationship elem ent has five attributes." The nam e attribute assigns a nam e to the relationship for subsequentreference in the schem a." The parent attribute denotes the parent row source, or one side, of theone-to-m any relationship between Shippers and Orders.(Each shipper canhave m any orders.)" The parent-key attribute denotes the field in the parent row source forlinking the parent and child row sources." The child and child-key attributes point to the m any side of the one-to-m any relationship.The Shipvia field in the Orders table is a foreign keypointing to the ShipperI D field in the Shippers table [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • higrostat.htw.pl
  •