Successfully reported this slideshow.
Your SlideShare is downloading. ×

XML Technologies

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Xml
Xml
Loading in …3
×

Check these out next

1 of 50 Ad

More Related Content

Advertisement

More from hamsa nandhini (17)

Recently uploaded (20)

Advertisement

XML Technologies

  1. 1. UNIT III XML TECHNOLOGIES
  2. 2. XPath • expressions that can be used to find specific pieces of information within an XML document. • Used by XPointer and XSLT. • It locate nodes based on the nodes’ type, name, or value or by the relationship of the nodes to other nodes within the XML document. • It returns: • A node set • A Boolean value • A string value • A numeric value
  3. 3. Operators and Special Characters • / • // • . • * • @ • : • () • [expression] • [n] • +,-,div,*,mod
  4. 4. Example <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book> <title lang="en">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="en">Learning XML</title> <price>39.95</price> </book> </bookstore>
  5. 5. XPath syntax • axis::node test[predicate] • Axis: Ancestor Ancestor-or-self Attribute Child Descendant Descendant-or-self Following Following-sibling Namespace Parent Preceding Preceding-sibling self
  6. 6. Example <book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
  7. 7. Node test • indicates the type of node desired for the results. • list of these node tests: • comment() • node() • processing-instruction() • text()
  8. 8. Predicate • filters a node set on the specified axis to create a new node set. • Forward / reverse axis predicate.
  9. 9. Xpath function • Boolean Boolean(object) False() Lang(string) Not(expression) True()
  10. 10. • Node set Count(node-set) Document(variant, [node-set]) Id(object) Key(name,value) Last() Local-name([node-set]) name([node-set]) Namespace-uri([node-set]) Position()
  11. 11. • Number Ceiling(number) Floor(number) Number(variant) round (number) Sum(node-set)
  12. 12. • String Concat(String,string,[string*]) Contains(string,string) Normalize-space() Starts-with(string,string) string(variant) String-length(string) Substring(string,start,length) Substring-after(string,string) Substring-before(char,replace) Translate(string,chars,replace)
  13. 13. XPointers • describes a location within an external document. • can target a point within that XML document or a range within the target XML document. • XPointer provides two more important node tests: • point() • range()
  14. 14. • Functions that return location set: id(), root(), here(), origin(). • Points: node point & character points. • Range functions: end-point(), range-inside(), range-to(), start-point().
  15. 15. Example <People> <Person> <Name>Dillon Larsen</Name> <Address> <Street>123 Jones Rd.</Street> <City>Houston</City> <State>TX</State> <Zip>77380</Zip> </Address> </Person>…… ----------/People/Person[1]/Name/text()/point()[position()=4] ----------/People/Person[1]/Name/text()/start-point()[position()=0]
  16. 16. XLink • allowing a link to another document to be specified on any element within an XML document. • creates a link to another resource through the use of attributes specified on elements, not through the actual elements themselves.
  17. 17. Xlink attributes 1. Xlink:type 2. Xlink:href 3. Xlink:role 4. Xlink:arcrole 5. Xlink:title 6. Xlink:show 7. Xlink:actuate 8. Xlink:label 9. Xlink:from 10. Xlink:to
  18. 18. • Xlink:type ---- simple, extended, locator, arc, resource, title, none. • Xlink:role ---- extended, simple, locator, resource. • Xlink:arcrole ---- arc, simple • Xlink:show ---- new, replace, embed, other, none. • Xlink:actuate ---- onLoad, onRequest, other, none.
  19. 19. Types of link • Simple links: • consists of an xlink:type attribute with a value of simple and, optionally, an xlink:href attribute with a specified value. • acts as a resourceXLink type for the local document. • They link exactly two resources together: one local and one remote. • Extended links: • to specify relationships between an unlimited number of resources, both local and remote.
  20. 20. XSL Technologies • XSL has two languages: • XSLT • XSL-FO
  21. 21. XSLT for document Publishing • Use XSL to convert XML into HTML,PDF,… • For WAP, convert XML to WML
  22. 22. Book.xml <?xml version=”1.0”?> <?xml-stylesheet type=”text/xsl” href=”book_view.xsl”?> <book> <author>Michael Daconta et al</author> <title>XML Development with Java 2</title> <category>Java</category> <price currency=”USD”>44.99</price> <summary> XML Development with Java 2 provides the information and techniques a Java developer will need to integrate XML into Java-based applications. </summary> </book>
  23. 23. Book_view.xsl <?xml version=”1.0”?> <xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” version=”1.0”> <xsl:template match=”/book”> <html><body> <b>Title: </b> <xsl:value-of select=”title” /><p/> <b>By: </b> <xsl:value-of select=”author” /><p/> <b>Cost: </b> <xsl:value-of select=”price” /><p/> <b>Category: </b> <xsl:value-of select=”category” /><p/> <b>Description</b><p/> <i><xsl:value-of select=”summary” /></i> </body></html> </xsl:template> </xsl:stylesheet>
  24. 24. Output
  25. 25. XSLT processor
  26. 26. XSLT processing • Two techniques: client-side XSLT & server-side XSLT processing. • Client-side: two files • Server-side technologies: CGI, coldfusion, PHP,ASP,JSP,…
  27. 27. ASP: Server-Side XSLT Processing • The required components: • Microsoft IIS Web Server 5.0 • Microsoft XML Parser 3.0. • Two options for publishing the source code on the IIS server: • Copy the files in <install_dir>ch9_xslpublic_html to c:Inetpubwwwroot. • Set up a virtual directory that points to <install_dir>ch9_xslpublic_html
  28. 28. <install_dir>ch9_xslpublic_htmlbook_test. asp <%@ Language=VBScript %> <% set xml = Server.CreateObject(“Microsoft.XMLDOM”) xml.load(Server.MapPath(“book.xml”)) set xsl = Server.CreateObject(“Microsoft.XMLDOM”) xsl.load(Server.MapPath(“book_view.xsl”)) Response.Write(xml.transformNode(xsl)) %>
  29. 29. JSP: Server-Side XSLT Processing • The required components: • Sun Microsystems’ Software Development Kit (SDK) 1.3 (or higher) • Apache Tomcat Server 4. • <install_dir>ch9_xslpublic_htmlbook_test.jsp: <%@ taglib uri=”http://jakarta.apache.org/taglibs/xsl-1.0” prefix=”jakarta” %> <jakarta:apply xml=”book.xml” xsl=”book_view.xsl” />
  30. 30. Advanced Features of XSLT • Looping • Sorting • Sorting: ascending/descending • Sorting by case • Sorting with multiple keys • Conditionals • Filters
  31. 31. Looping • Syntax: <xsl:for-each select=node-set-expression> <!-- content --> </xsl:for-each>
  32. 32. Example
  33. 33. Sorting • Syntax: <xsl:sort select = string-expression order = { “ascending” | “descending” } data-type = { “text” | “number” } case-order = {“upper-first” | “lower-first” } lang = { nmtoken } />
  34. 34. Ascending/descending <!-- Sort by the book title, descending --> <xsl:for-each select=”booklist/book”> <xsl:sort select=”title” order=”descending”/> <!-- insert table rows and table data --> </xsl:for-each>
  35. 35. Sorting with multiple key
  36. 36. Conditionals • Syntax: <xsl:if test=Boolean-expression> <!-- content --> </xsl:if>
  37. 37. Filters
  38. 38. XSL-FO • to assist with the printing and displaying of XML data. • Focus on the document layout and structure. • Version of CSS.
  39. 39. Document structure
  40. 40. XSL-FO document components: •Page master •Page master set •Page sequences
  41. 41. Page Master: <fo:page-master> • describes the page size and layout. • <fo:simple-page-master>element defines the layout of a page. Eg: <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> </fo:simple-page-master>
  42. 42. Components of page master
  43. 43. Five regions of a page <fo:region-before> <fo:region-after> <fo:region-body> <fo:region-start> <fo:region-end> Eg: <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”0.5in”/> <fo:region-after extent=”0.5in”/> </fo:simple-page-master>
  44. 44. Page Master Set: <fo:page-master-set> <fo:layout-master-set> <fo:simple-page-master master-name=”simple” page-height=”11in” page-width=”8.5in” margin-top=”1in” margin-bottom=”1in” margin-left=”1.25in” margin-right=”1.25in”> <fo:region-body margin-top=”0.5in”/> <fo:region-before extent=”3cm”/> <fo:region-after extent=”1.5cm”/> </fo:simple-page-master> </fo:layout-master-set>
  45. 45. Page Sequences: <fo:page-sequence> • Contains Two elements: • <fo:static-content>, • <fo:flow>: 2 <fo:block>elements
  46. 46. Generating a PDF Document Steps to generate a PDF document from simple.fo: 1. Open an MS-DOS window. 2. Move to the directory <install_dir>ch9_xslxsl_fo. 3. Set up the Java classpath by typing setpaths. 4. Execute Apache-FOP by typing fop simple.fo simple.pdf. The Apache- FOP formatter now reads the input file simple.foand generates the output file simple.pdf. 5. View the simple.pdffile in Adobe Acrobat Reader.
  47. 47. Page Headers and Footers • <fo:static-content>
  48. 48. Graphics • insertion of external graphic images. • Eg: <fo:block text-align=”center”> <fo:external-graphic src=”smiley.jpg” width=”200px” height=”200px”/> </fo:block>
  49. 49. Tables
  50. 50. Structure for the table

×