Includes the XML document test.xml in the current XML document.Element includer is an include element, with the required XInclude href attribute for referencing an XML document.To include portions of another XML document,Xpointer can be used in the xinclude attribute href.The optional xinclude attribute parse can have value xml or text. The default value,xml parses the XML document as XML for inclusion ; thus any entities,include elements and other parsable items are processed before being embedded into xml document.Using the value text in the parse attribute incorporates the document referenced as plain –text character data,which is not parsed. Xinclude differs from xlink : show = “ embed” in that it merges the tree structures of the two documents into a single tree."> Includes the XML document test.xml in the current XML document.Element includer is an include element, with the required XInclude href attribute for referencing an XML document.To include portions of another XML document,Xpointer can be used in the xinclude attribute href.The optional xinclude attribute parse can have value xml or text. The default value,xml parses the XML document as XML for inclusion ; thus any entities,include elements and other parsable items are processed before being embedded into xml document.Using the value text in the parse attribute incorporates the document referenced as plain –text character data,which is not parsed. Xinclude differs from xlink : show = “ embed” in that it merges the tree structures of the two documents into a single tree.">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is XLink? XLink is short for XML Linking Language XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as.

Similar presentations


Presentation on theme: "What is XLink? XLink is short for XML Linking Language XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as."— Presentation transcript:

1 What is XLink? XLink is short for XML Linking Language XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as a link. Xlink elements that specify linking information are called linking elements XLink supports simple links (like HTML) and extended links (for linking multiple resources together) With XLink, the links can be defined outside the linked files XLink is a W3C Recommendation XLink is capable of linking more than just documents; XLink links resources which includes documents,audio,video,database data,etc. Web Browsers will eventually support XLink. However,XLink is intended for a broader base of applications, not just Web browsers. What is XPointer? XPointer is short for XML Pointer Language XPointer allows the links to point to specific parts of an XML document XPointer uses XPath expressions to navigate in the XML document XPointer is a W3C Recommendation.

2 XLink Syntax In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what hyperlink elements will be called in XML documents. The solution for creating links in XML documents was to put a marker on elements that should act as hyperlinks. Visit W3Schools Visit W3C xlink:show="new"> To get access to the XLink attributes and features we must declare the XLink namespace at the top of the document.The XLink namespace is: "http://www.w3.org/1999/xlink". The xlink:type and the xlink:href attributes in the elements define that the type and href attributes come from the xlink namespace. The xlink:type="simple" creates a simple, two-ended link (means "click from here to go there"). The href attribute is required. We will look at multi-ended (multidirectional) links later.

3 The xlink:show attribute is set to "new". This means that the link should open in a new window. We could have set the value of the xlink:show attribute to "embed". This means that the resource should be processed inline within the page. When you consider that this could be another XML document and not just an image, you could, for example, build a hierarchy of XML documents. With XLink, you can also specify WHEN the resource should appear. This is handled by the xlink:actuate attribute. xlink:actuate="onLoad" specifies that the resource should be loaded and shown when the document loads. However, xlink:actuate="onRequest" means that the resource is not read or shown before the link is clicked. This is very handy for low-bandwidth(infornation carrying capacity of a line) settings. XML Inclusions (XInclude) Concept was introduced to add one XML document inside another, an include element is used. An include element is any XML element that has particular attributes from the namespace http://www.w3.org/1999/XML/xinclude. <includer xmlns : xinclude = “http : // www.w3.org/1999/XML/xinclude” xinclude : href = “test.xml” xinclude : parse = “xml”/> Includes the XML document test.xml in the current XML document.Element includer is an include element, with the required XInclude href attribute for referencing an XML document.To include portions of another XML document,Xpointer can be used in the xinclude attribute href.The optional xinclude attribute parse can have value xml or text. The default value,xml parses the XML document as XML for inclusion ; thus any entities,include elements and other parsable items are processed before being embedded into xml document.Using the value text in the parse attribute incorporates the document referenced as plain –text character data,which is not parsed. Xinclude differs from xlink : show = “ embed” in that it merges the tree structures of the two documents into a single tree.

4 Pointer Syntax Sometimes it is more useful to point to more specific content. For example, let's say that we want to link to the third item in a particular list, or to the second sentence of the fifth paragraph. This is easy with XPointer. If the hyperlink points to an XML document, we can add an XPointer part after the URL in the xlink:href attribute,to navigate (with an XPath expression) to a specific place in the document. For example, in the example below we use XPointer to point to the fifth item in a list with a unique id of "rock": href=http://www.example.com/cdlist.xml#id(' rock').child(5,item)http://www.example.com/cdlist.xml#id(' rock').child(5,item)

5 XPointer Example Confident, bold, alert and imposing, the Rottweiler is a popular choice for its ability to protect.... Anton is my favorite dog. He has won a lot of..... So the xlink:href attribute would look like this: xlink:href="http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))" However, XPointer allows a shorthand form when linking to an element with an id. You can use the value of the id directly, like this: xlink:href="http://dog.com/dogbreeds.xml#Rottweiler"

6 Dietel,Harvery Dietel, Paul With XLink, we can refer the entire contact list with the URI xlink : href = “ /contacts.xml ” We can use Xpointer expression xlink:href = “/contacts.xml#xpointer(//contact[@id = ‘author02’])” The name xpointer called a scheme expresses the full Xpointer form. To reference the contact element with an id of author02 Xpointer also provides abbreviations for expressions that use attribute id. For example, if a documents unique identifier is referenced in any expression such as xlink : href = “/contacts.xml#xpointer(id(‘author01’])” The expression can be simplified by writing :- xlink : href = “/contacts.xml#author01” which is a bare name Xpointer address.

7 XQuery XQuery is to XML what SQL is to database tables. XQuery was designed to query XML data.,XQuery is built on XPath expressions XQuery is supported by all major databases,XQuery is a W3C Recommendation XQuery is a language for finding and extracting elements and attributes from XML documents XQuery is case sensitive.SQL keywords are not case sensitive. XQuery can be used to:- Extract information to use in a Web Service,Generate summary reports Transform XML data to XHTML, Search Web documents for relevant information When the data is measured in gigabytes, creating an in-memory DOM becomes impractical in many situations

8 We will use the following XML document in the examples below "books.xml": Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 Learning XML Erik T. Ray 2003 39.95

9 The doc( ) function is used to open the "books.xml" file: doc("books.xml")/bookstore/book/title(/bookstore selects the bookstore element, /book selects all the book elements under the bookstore element, and /title selects all the title elements under each book element) The XQuery above will extract the following: Everyday Italian Harry Potter XQuery Kick Start Learning XML The following predicate is used to select all the book elements under the bookstore element that have a price element with a value that is less than 30: doc("books.xml")/bookstore/book[price<30] Harry Potter J K. Rowling 2005 29.99

10 XQuery FLWOR Expressions They are power of XQuery. It owes much to the SELECT statement in SQL. doc("books.xml")/bookstore/book[price>30]/title The following FLWOR expression will select exactly the same as the path expression above: for $x in doc("books.xml")/bookstore/book where $x/price>30 return $x/title The result will be: Learning XML With FLWOR you can sort the result: for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title return $x/title FLWOR is an acronym for "For, Let, Where, Order by, Return". The for clause selects all book elements under the bookstore element into a variable called $x. The where clause selects only book elements with a price element with a value greater than 30. The order by clause defines the sort-order. Will be sort by the title element. The return clause specifies what should be returned. Here it returns the title elements. The result of the XQuery expression above will be: Learning XML

11 Now we want to list all the book-titles in our bookstore in an HTML list. We add and tags to the FLWOR expression: { for $x in doc("books.xml")/bookstore/book/title order by $x return {$x} } The result of the above will be: Everyday Italian Harry Potter Learning XML Now we want to eliminate the title element, and show only the data inside the title element: { for $x in doc("books.xml")/bookstore/book/title order by $x return {data($x)} } The result will be (an HTML list): Everyday Italian Harry Potter Learning XML

12 XQuery Conditional Expressions "If-Then-Else" expressions are allowed in XQuery. Look at the following example: for $x in doc("books.xml")/bookstore/book return if ($x/@category="CHILDREN") then {data($x/title)} else {data($x/title)} Notes on the "if-then-else" syntax: parentheses around the if expression are required. else is required, but it can be just else ( ). The result of the example above will be:---- Everyday Italian Harry Potter Learning XML

13 XQuery Adding Elements Bookstore { for $x in doc("books.xml")/bookstore/book order by $x/title return {data($x/title)}. Category: {data($x/@category)} } Bookstore Everyday Italian. Category: COOKING Harry Potter. Category: CHILDREN Learning XML. Category: WEB XQuery Kick Start. Category: WEB

14 XQuery Adding Attributes Next, we want to use the category attribute as a class attribute in the HTML list: Bookstore { for $x in doc("books.xml")/bookstore/book order by $x/title return {data($x/title)} } The XQuery expression above will generate the following result: Bookstore Everyday Italian Harry Potter Learning XML XQuery Kick Start

15 Selecting and Filtering Elements As we have seen in the previous chapters, we are selecting and filtering elements with either a Path expression or with a FLWOR expression. Look at the following FLWOR expression: for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title return $x/title for - (optional) binds a variable to each item returned by the in expression let - (optional) where - (optional) specifies a criteria order by - (optional) specifies the sort-order of the result return - specifies what to return in the result The for Clause The for clause binds a variable to each item returned by the in expression. The for clause results in iteration. There can be multiple for clauses in the same FLWOR expression. To loop a specific number of times in a for clause, you may use the to keyword: for $x in (1 to 5) return {$x} Result:- 1 2 3 4 5

16 The at keyword can be used to count the iteration: for $x at $i in doc("books.xml")/bookstore/book/title return {$i}. {data($x)} Result: 1. Everyday Italian 2. Harry Potter 3. XQuery Kick Start 4. Learning XML It is also allowed with more than one in expression in the for clause. Use comma to separate each in expression: for $x in (10,20), $y in (100,200) return x={$x} and y={$y} Result: x=10 and y=100 x=10 and y=200 x=20 and y=100 x=20 and y=200 The let clause allows variable assignments and it avoids repeating the same expression many times. The let clause does not result in iteration. let $x := (1 to 5) return {$x} Result: 1 2 3 4 5 The where Clause The where clause is used to specify one or more criteria for the result: where $x/price>30 and $x/price<100The order by Clause

17 The order by clause is used to specify the sort order of the result. Here we want to order the result by category and title: for $x in doc("books.xml")/bookstore/book order by $x/@category, $x/title return $x/title Harry Potter Everyday Italian Learning XML XQuery Kick Start The return Clause The return clause specifies what is to be returned. for $x in doc("books.xml")/bookstore/book return $x/title Everyday Italian Harry Potter XQuery Kick Start Learning XML

18 XQuery Functions XQuery includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more. You can also define your own functions in XQuery. Examples of Function Calls A call to a function can appear where an expression may appear. Look at the examples below: Example 1: In an element {uppercase($booktitle)} Example 2: In the predicate of a path expression doc("books.xml")/bookstore/book[substring(title,1,5)='Harry'] Example 3: In a let clause let $name := (substring($booktitle,1,4))

19 The concat( ) function To be or not to be, that is the question ! The saying Asaying.xquery, is shown here { for $a in doc(“Parts.xml”)/Parts/Part[1] for $b in doc(“Parts.xml”)/Parts/Part[2] return concat($a, $b) }

20 XQuery User-Defined Functions If you cannot find the XQuery function you need, you can write your own. User-defined functions can be defined in the query or in a separate library. Syntax declare function prefix:function_name($parameter AS datatype) AS returnDatatype {...function code here... } Notes on user-defined functions: Use the declare function keyword The name of the function must be prefixed The data type of the parameters are mostly the same as the data types defined in XML Schema The body of the function must be surrounded by curly braces Example of a User-defined Function Declared in the Query declare function local:minPrice($p as xs:decimal?, $d as xs:decimal?) AS xs:decimal? { let $disc := ($p * $d) div 100 return ($p - $disc) } Below is an example of how to call the function above: {local:minPrice($book/price,$book/discount)}


Download ppt "What is XLink? XLink is short for XML Linking Language XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as."

Similar presentations


Ads by Google