SlideShare a Scribd company logo
Introduction to XML Svetlin Nakov Bulgarian Association of Software Developers www.devbg.org
Contents What is XML? XML and HTML When to use XML? Namespaces Schemes and validation – DTD  and XSD schemes XPath Language XSL XSL transformations
What is XML
What is XML? Universal language (notation) for describing structured data The data is stored together with the meta-information about it Looks like HTML – text based, uses tags  and attributes It is used to describe other languages (formats) for data representation
What is XML? (2) Worldwide-affirmative   standard, supported by the W3C (www.w3c.org) Platform, programming languages and OS independent
XML - Example <?xml version=&quot;1.0&quot;?> <library name=&quot;.NET Developer's Library&quot;> <book> <title>Programming Microsoft .NET</title> <author>Jeff Prosise</author> <isbn>0-7356-1376-1</isbn> </book> <book> <title>Microsoft .NET for Programmers</title> <author>Fergal Grimes</author> <isbn>1-930110-19-7</isbn> </book> </library>
XML  –  Example <?xml version=&quot;1.0&quot;?> <library  name=&quot;.NET Developer's Library&quot; > <book> <title>Programming Microsoft .NET</title> <author>Jeff Prosise</author> <isbn>0-7356-1376-1</isbn> </book> <book> <title>Microsoft   .NET for Programmers</title> <author>Fergal Grimes</author> <isbn> 1-930110-19-7 </isbn> </book> </library> attribute header part  ( prolog ) element closing tag element value opening tag
XML   and HTML Likenesses between   XML   and   HTML : Both are text based Both use tags and attributes Differences between XML and HTML: HTML is a language, and XML is a  syntax for describing other languages HTML describes the formatting of information, and XML describes structured information XML requires the documents to be  well-formed
Well-Formed Documents XML requires the documents to be well-formed Tags should always be closed in the right order Attributes should always be closed The document should contain only one root element There are restrictions of the tag and attribute names
Well-Formed Documents (2) Example of bad-defined XML document < xml> <button bug! value=&quot;OK name=&quot;b1&quot;> <animation source=&quot;demo1.avi&quot;>  1 < 2 < 3 </click-button> < / xml >
When to Use   XML? Use XML : For information exchange between different systems For storing structured data To create custom-defined languages for describing information Configuration data
XML Disadvantages XML disadvantages: Data is more massive (take more space) Decreased performance Frequently there is a need of more memory Increased network traffic
Namespaces
Namespaces Namespaces in XML documents add the possibility to use different tags with the same name : <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <country:towns xmlns:country=&quot;urn:nakov-com:country&quot; xmlns:town=&quot;http:// www. nakov.com/town&quot;> <town:town> <town:name> Sofia </town:name> <town:population>1 200 000</town:population> <country:name> Bulgaria </country:name> </town:town> <town:town> <town:name>Plovdiv</town:name> <town:population>700 000</town:population> <country:name>Bulgaria</country:name> </town:town> </country:towns>
Namespaces - Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <country:towns  xmlns:country=&quot;urn:nakov-com:country&quot; xmlns:town=&quot;http:// www. nakov.com/town&quot;> <town:town> <town:name>Sofia</town:name> <town:population>1 200 000</town:population> <country:name>Bulgaria</country:name> </town:town> <town:town> <town:name>Plovdiv</town:name> <town:population>700 000</town:population> <country:name> Bulgaria </country:name> </town:town> </country:towns> Namespace with prefix  &quot; country &quot;  and  URI  identifier  &quot; urn:nakov-com:country &quot; Tag with name  &quot; name &quot;  from namespace  &quot; country &quot;,  the full name is  &quot; urn:nakov-com:country:name &quot;
Namespaces (2) It is possible to use default namespaces <?xml version=&quot;1.0&quot; encoding=&quot;windows-1251&quot;?> <order  xmlns=&quot;http://www.hranitelni-stoki.com/orders&quot; > <item> <name>бира &quot;Загорка&quot;</name> <ammount> 8 </ammount> <measure>бутилка</measure> <price> 3 . 76 </price> </item> <item> <name>кебапчета</name> <ammount>12</ammount> <measure>брой</measure> <price> 4.20 </price> </item> </order>
XML Schemes and Validation
Schemes and Validation The XML documents structure is defined  by schemes Schemes describes Possible tags Possible attributes Possible values for the attributes and elements Order of the tags Default values
The   DTD Language DTD  ( Document Type Definition )  is : Formal language for describing XML document structures Contains sum of rules for the tags and their attributes in a document Text-based language, but not XML  based Rarely used because it is substituted  by XSD
The   DTD Language (2) DTD Example: <!ELEMENT library (book+)> <!ATTLIST library name CDATA #REQUIRED > <!ELEMENT book (title, author, isbn)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT  isbn  (#PCDATA)>
XSD Schemes XSD (XML Scheme Definition Language) is: Powerful XML-based language for describing the structure of XML documents Contains sum of rules for the tags  and their attributes is a document XSD schemes have bigger descriptive  power than the DTD XSD consequently replaces   DTD
XSD Scheme Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <xs:schema   xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xs:element name=&quot;library&quot;> <xs:complexType> <xs:sequence> <xs:element ref=&quot;book&quot; maxOccurs=&quot;unbounded&quot;/> </xs:sequence> <xs:attribute name=&quot;name&quot; type=&quot;xs:string&quot;   use=&quot;optional&quot;/> </xs:complexType> </xs:element>   (the example continues)
XSD Scheme Example (2) <xs:element name=&quot;book&quot;> <xs:complexType> <xs:sequence> <xs:element ref=&quot;title&quot;/> <xs:element ref=&quot;author&quot;/> <xs:element ref=&quot;isbn&quot;/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=&quot;title&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;author&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;isbn&quot; type=&quot;xs:string&quot;/> </xs:schema>
XPath
XPath XPath (XML Path Language) is a language for addressing parts of XML documents XPath expressions contains description of paths to nodes and criteria, which the nodes should pass XPath is frequently used with XSLT and XPointer Example for XPath expressions: /library/book[isbn= ' 1-930110-19-7 ' ] /catalog/cd[ @ price < 10.80]
XPath   Expressions /  – addresses the root element /someNode  – addresses all nodes with name &quot; someNode &quot;,  direct  inheritors to the root /books/book  – addresses all nodes  &quot; book &quot;  ,  direct  inheritors to the node &quot; books &quot; /books/book[price<&quot;10&quot;]/author  – addresses all authors ( /books/book/ author ), whose books have price < &quot; 10 &quot;   /items/item[@type=&quot;food&quot;]  – addresses all nodes with name  item , which have attribute &quot; type &quot; with value &quot; food &quot;  and are inheritors to the &quot; items &quot; node
XSL
XSL for Cross - Media Publishing PDF as  digital preprint HTML a s  standard  I nternet  F ormat For Online  P ublishing Author writes in text  processing system using style sheets System saves as/ converts to XML <XML-Document> Catalogue entry MARC-Format Library catalogue XSLT-Stylesheet XSLT-Stylesheet XSLT-Stylesheet
XSL Transformation Language (XSLT)
What is XSLT? XSLT stands for XSL Transformations XSLT transforms an XML document into another  text format  document U ses XPath to navigate in  the  XML document XSLT is a W3C Recommendation
XSL/XSLT Capabilities  Add prefix or suffix text to content Remove, create, re-order and sort elements Re-use elements elsewhere in the document Transform data between XML formats Specify the XSL formatting objects to be applied to each element class Uses a recursive mechanism to go through document
Browsers Support Note:  Not all browsers  have full support for XML and XSLT  Internet Explorer 6  – full support Mozilla 1.7.8   -  is available with an  XSLT implementation Netscape 8  -  based on the Mozilla engine. Same XML / XSLT support as Mozilla Opera 8  -  supports XML + CSS
Simple XML <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <catalog> <cd> <title> Evergreens </title> <artist></artist> <country>USA</country> <company> USA Music Enterprise </company> <price>1 2 . 0 0</price> <year>198 0 </year>  </cd> . . .  </catalog>  First we have a XML document catalog.xml
Create an XSL Style Sheet <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;> <html> <body> <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> Then  create an XSL Style Sheet  ( cdc.xsl )
Link the XSL Style Sheet to the XML Document A XML document can be linked explicitly to a XSL transformation document Use processing instruction  <?xml-stylesheet ?> <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot;  href=&quot;cdc.xsl&quot;?> <catalog> ... </catalog>
Output Format Control <xsl:stylesheet xmlns:xsl= . . .> <xsl:output method= &quot; html &quot;   encoding= &quot; UTF-8 &quot;  … /> <xsl:template  match = &quot; / &quot; > <HTML>…</HTML> </xsl:template> </xsl:stylesheet> Define output as XML, HTML, or text Can specify the character encoding Control the XML declaration and  DOCTYPE
XSLT Specification Available from  http://www.w3.org/XSL/ Defines 34 elements and their attributes Can build useful style sheets using stylesheet template apply-templates Depends on the XPath specification
Template Element Template element specifies transformation rule The match attribute takes XPath expressions If more than one XPath matches – then use priority rules to determine which is used  <xsl:template match=&quot;/&quot;>   … </xsl:template>
Import Element Use import element to include multiple XSLT files <stylesheet … >   < import  href=&quot;tables.xsl&quot;/>   < import  href=&quot;features.xsl&quot;>   <template … > … </template>   …  </stylesheet>
The <xsl:value-of> Element U sed to extract the value of an XML element  Note: The value of the  select  attribute  is an XPath expression  ... <xsl:value-of select=&quot;catalog/cd/title&quot;/> <xsl:value-of select=&quot;catalog/cd/artist&quot;/> ...
The <xsl:for-each> Element U sed to select every XML element of a specified node-set  (in a loop) Note: The value of the  select  attribute  is an XPath expression  ... <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body> ...
The <xsl:for-each> Element  Filter output We can also filter the output from the XML <xsl:for-each select=&quot;catalog/cd[artist='Bob  Dylan ']&quot;>  We use expressions in square brackets [ ... ] for setting conditions Legal operator are: =  (equal)  != (not equal)  &lt; less than  &gt; greater than
XSLT <xsl:sort> Element U sed to sort the output Add this element  inside the  <xsl:for-each> element  Note: The  select   attribute indicates what XML element to sort on <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:sort select=&quot;artist&quot;/> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body>
Sort Element Properties The ' order ' attribute ' ascending ' or ' descending ' The ' data-type ' attribute ' text ' (default) or ' number ' The ' case-order ' attribute ' lower-first ' or ' upper-first ' <xsl:sort select=&quot; product/price &quot; data-type=&quot;number&quot; order=&quot;descending&quot; />
The <xsl:if> Element U sed to put a conditional test against  the content of the XML file Note:  The value of the required test attribute contains the expression to be evaluated <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:if test=&quot;price &gt; 10&quot;>   <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:if> </xsl:for-each> </body>
The <xsl:choose> Element U sed in conjunction with  <xsl:when>  and  <xsl:otherwise> t o express multiple conditional tests  <xsl:choose> <xsl:when test=&quot;XPath  expression &quot;>  ... some output ...  </xsl:when> <xsl:otherwise>   ... some output ....  </xsl:otherwise> </xsl:choose>
The  <xsl:apply-templates>   Element A pplies a template to the current element or to the current  element's  child nodes S elect attribute  –  will process only the child element that matches the value of the attribute  Note:  The value of the required  select  attribute is a XPath expression <xsl:template match=&quot;cd&quot;> <p> <xsl:apply-templates select=&quot;title&quot;/> </p> </xsl:template> <xsl:template  match=&quot;title&quot; >  Title:  <xsl:value-of select=&quot;.&quot;/> <br />  </xsl:template>
Variable Element Variables may be declared and used in XSLT Variable is referenced with  $  notation <xsl:variable name=&quot;colour&quot;>red</xsl:variable> <xsl:value-of select=&quot;$colour&quot;/>
Reusing Templates If same formatting is required many times //   A named template called by call-template <xsl:template  name=&quot;CreateHeader&quot; >   <html:hr/>   <html:h2>***<xsl:apply-templates/>***</html:h2>   <html:hr/> </xsl:template> ... <xsl:template match=&quot;title&quot;>   < xsl:call-template  name=&quot;CreateHeader&quot; /> </xsl:template> <xsl:template match=&quot;head&quot;>   < xsl:call-template  name=”CreateHeader&quot; /> </xsl:template>
Attribute Values Use ' value-of ' element to access attributes Attributes identified by ' @ ' prefix <full-name first=&quot;John&quot; second=&quot;Smith&quot;/> ----------------------------------------- <xsl:template match=&quot;full-name&quot;>   <ajr:person>   <xsl:value-of  select=&quot;@first&quot; >    <xsl:value-of  select=&quot;@second&quot; >   </ajr:person>   <ajr:person name=&quot;{@first} {@second}&quot; /> </xsl:template> ----------------------------------------- <ajr:person>John Smith</ajr:person> <ajr:person name=&quot;John Smith&quot;/>
Creating Elements Use ' Element ' tag to create new elements Most powerful with use of variables <xsl:template match= &quot; name &quot; > <xsl:element name= &quot; {.}&quot;>   Nice person!   </xsl:element> </xsl:template> <name>Gosho</name Input <Gosho> Nice person! </Gosho> Result
XSLT Live Demo
Introduction to XML Questions?
Exercises What does the XML language represents ?  What is it used for?   When do we use it ? Create an XML document  students.xml ,  which contains structured description of students. For each student you should  enter information for his name, sex, birth  date, phone, course, specialty, faculty  number and a list of taken exams (exam name, tutor, grade). What does the namespaces represent in the XML documents? What are they used for? When do we used them?
Exercises (2) Add default namespace for the students  &quot; urn:students &quot; . Write an XML file containing orders. Each order is described by date, customer name and a list of order items. Each order item consists of product name, amount and price.  Write an XSL stylesheet to transform the XML file to a human readable XHTML document. Sort the products in alphabetical order. Test the produced XHTML file in your Web browser.
Exercises (3) Write your CV in XML format. It should have the following structure: Personal information (name, DOB, ...) Education Skills Work experience ... Write a XSL stylesheet for transforming the CV to HTML and XML with other structure.
Ad

More Related Content

What's hot (20)

XML
XMLXML
XML
Daminda Herath
 
XML
XMLXML
XML
Mukesh Tekwani
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Bình Trọng Án
 
Xml
XmlXml
Xml
Dr. C.V. Suresh Babu
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
Gtu Booker
 
XML
XMLXML
XML
Vahideh Zarea Gavgani
 
Xml
XmlXml
Xml
Santosh Pandey
 
XML-Extensible Markup Language
XML-Extensible Markup Language XML-Extensible Markup Language
XML-Extensible Markup Language
Ann Joseph
 
Extensible Markup Language (XML)
Extensible Markup Language (XML)Extensible Markup Language (XML)
Extensible Markup Language (XML)
AakankshaR
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Abhra Basak
 
Basic xml syntax
Basic xml syntaxBasic xml syntax
Basic xml syntax
Raghu nath
 
Xml tutorial
Xml tutorialXml tutorial
Xml tutorial
IT
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
Pradeep Rapolu
 
Intro xml
Intro xmlIntro xml
Intro xml
sana mateen
 
Xml ppt
Xml pptXml ppt
Xml ppt
seemadav1
 
Xml presentation
Xml presentationXml presentation
Xml presentation
Miguel Angel Teheran Garcia
 
01 Xml Begin
01 Xml Begin01 Xml Begin
01 Xml Begin
Dennis Pipper
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
Abhishek Kesharwani
 
XML
XMLXML
XML
Osama Qunoo
 
Basic XML
Basic XMLBasic XML
Basic XML
Hoang Nguyen
 

Viewers also liked (17)

Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
yht4ever
 
Xml
XmlXml
Xml
madhavforu
 
10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
koolkampus
 
Lecture #2 xml
Lecture #2 xmlLecture #2 xml
Lecture #2 xml
Adil Alpkoçak
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
Duncan Davies
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
Pradeep Kumar
 
Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy
Adz91 Digital Ads Pvt Ltd
 
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easyIEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEEFINALYEARSTUDENTPROJECTS
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
Aditya Raj
 
Session 1
Session 1Session 1
Session 1
Lại Đức Chung
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
Alfonso Gabriel López Ceballos
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
yht4ever
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
srinivasanjayakumar
 
XML.ppt
XML.pptXML.ppt
XML.ppt
butest
 
Xml dtd
Xml dtdXml dtd
Xml dtd
sana mateen
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)
Peter R. Egli
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
yht4ever
 
10. XML in DBMS
10. XML in DBMS10. XML in DBMS
10. XML in DBMS
koolkampus
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
Duncan Davies
 
Webservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
Pradeep Kumar
 
Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy
Adz91 Digital Ads Pvt Ltd
 
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easyIEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEEFINALYEARSTUDENTPROJECTS
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
Aditya Raj
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
yht4ever
 
XML.ppt
XML.pptXML.ppt
XML.ppt
butest
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)
Peter R. Egli
 
Ad

Similar to Introduction to XML (20)

Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
Stephan Schmidt
 
XMLT
XMLTXMLT
XMLT
Kunal Gaind
 
Intro XML for archivists (2011)
Intro XML for archivists (2011)Intro XML for archivists (2011)
Intro XML for archivists (2011)
Jane Stevenson
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
Andrew Savory
 
Xml
XmlXml
Xml
guestcacd813
 
About XML
About XMLAbout XML
About XML
David Rajah Selvaraj
 
Extensible Stylesheet Language
Extensible Stylesheet LanguageExtensible Stylesheet Language
Extensible Stylesheet Language
Jussi Pohjolainen
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
BG Java EE Course
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
Stephan Schmidt
 
Transforming Xml Data Into Html
Transforming Xml Data Into HtmlTransforming Xml Data Into Html
Transforming Xml Data Into Html
Karthikeyan Mkr
 
Introduction To Xml
Introduction To XmlIntroduction To Xml
Introduction To Xml
bdebruin
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
vikram singh
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
gauravashq
 
Xml
XmlXml
Xml
Vishwa Mohan
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
vikram singh
 
Xml
XmlXml
Xml
Kunal Gaind
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
guest53eac8
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Richard Davis
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
Stephan Schmidt
 
Intro XML for archivists (2011)
Intro XML for archivists (2011)Intro XML for archivists (2011)
Intro XML for archivists (2011)
Jane Stevenson
 
Extensible Stylesheet Language
Extensible Stylesheet LanguageExtensible Stylesheet Language
Extensible Stylesheet Language
Jussi Pohjolainen
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
Stephan Schmidt
 
Transforming Xml Data Into Html
Transforming Xml Data Into HtmlTransforming Xml Data Into Html
Transforming Xml Data Into Html
Karthikeyan Mkr
 
Introduction To Xml
Introduction To XmlIntroduction To Xml
Introduction To Xml
bdebruin
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
gauravashq
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
Lorna Mitchell
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
Digital + Container List
Digital + Container ListDigital + Container List
Digital + Container List
guest53eac8
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Richard Davis
 
Ad

More from BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
BG Java EE Course
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
JSTL
JSTLJSTL
JSTL
BG Java EE Course
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
BG Java EE Course
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
BG Java EE Course
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
CSS
CSSCSS
CSS
BG Java EE Course
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
BG Java EE Course
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
BG Java EE Course
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
BG Java EE Course
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
BG Java EE Course
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
BG Java EE Course
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
BG Java EE Course
 

Recently uploaded (20)

SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 

Introduction to XML

  • 1. Introduction to XML Svetlin Nakov Bulgarian Association of Software Developers www.devbg.org
  • 2. Contents What is XML? XML and HTML When to use XML? Namespaces Schemes and validation – DTD and XSD schemes XPath Language XSL XSL transformations
  • 4. What is XML? Universal language (notation) for describing structured data The data is stored together with the meta-information about it Looks like HTML – text based, uses tags and attributes It is used to describe other languages (formats) for data representation
  • 5. What is XML? (2) Worldwide-affirmative standard, supported by the W3C (www.w3c.org) Platform, programming languages and OS independent
  • 6. XML - Example <?xml version=&quot;1.0&quot;?> <library name=&quot;.NET Developer's Library&quot;> <book> <title>Programming Microsoft .NET</title> <author>Jeff Prosise</author> <isbn>0-7356-1376-1</isbn> </book> <book> <title>Microsoft .NET for Programmers</title> <author>Fergal Grimes</author> <isbn>1-930110-19-7</isbn> </book> </library>
  • 7. XML – Example <?xml version=&quot;1.0&quot;?> <library name=&quot;.NET Developer's Library&quot; > <book> <title>Programming Microsoft .NET</title> <author>Jeff Prosise</author> <isbn>0-7356-1376-1</isbn> </book> <book> <title>Microsoft .NET for Programmers</title> <author>Fergal Grimes</author> <isbn> 1-930110-19-7 </isbn> </book> </library> attribute header part ( prolog ) element closing tag element value opening tag
  • 8. XML and HTML Likenesses between XML and HTML : Both are text based Both use tags and attributes Differences between XML and HTML: HTML is a language, and XML is a syntax for describing other languages HTML describes the formatting of information, and XML describes structured information XML requires the documents to be well-formed
  • 9. Well-Formed Documents XML requires the documents to be well-formed Tags should always be closed in the right order Attributes should always be closed The document should contain only one root element There are restrictions of the tag and attribute names
  • 10. Well-Formed Documents (2) Example of bad-defined XML document < xml> <button bug! value=&quot;OK name=&quot;b1&quot;> <animation source=&quot;demo1.avi&quot;> 1 < 2 < 3 </click-button> < / xml >
  • 11. When to Use XML? Use XML : For information exchange between different systems For storing structured data To create custom-defined languages for describing information Configuration data
  • 12. XML Disadvantages XML disadvantages: Data is more massive (take more space) Decreased performance Frequently there is a need of more memory Increased network traffic
  • 14. Namespaces Namespaces in XML documents add the possibility to use different tags with the same name : <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <country:towns xmlns:country=&quot;urn:nakov-com:country&quot; xmlns:town=&quot;http:// www. nakov.com/town&quot;> <town:town> <town:name> Sofia </town:name> <town:population>1 200 000</town:population> <country:name> Bulgaria </country:name> </town:town> <town:town> <town:name>Plovdiv</town:name> <town:population>700 000</town:population> <country:name>Bulgaria</country:name> </town:town> </country:towns>
  • 15. Namespaces - Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <country:towns xmlns:country=&quot;urn:nakov-com:country&quot; xmlns:town=&quot;http:// www. nakov.com/town&quot;> <town:town> <town:name>Sofia</town:name> <town:population>1 200 000</town:population> <country:name>Bulgaria</country:name> </town:town> <town:town> <town:name>Plovdiv</town:name> <town:population>700 000</town:population> <country:name> Bulgaria </country:name> </town:town> </country:towns> Namespace with prefix &quot; country &quot; and URI identifier &quot; urn:nakov-com:country &quot; Tag with name &quot; name &quot; from namespace &quot; country &quot;, the full name is &quot; urn:nakov-com:country:name &quot;
  • 16. Namespaces (2) It is possible to use default namespaces <?xml version=&quot;1.0&quot; encoding=&quot;windows-1251&quot;?> <order xmlns=&quot;http://www.hranitelni-stoki.com/orders&quot; > <item> <name>бира &quot;Загорка&quot;</name> <ammount> 8 </ammount> <measure>бутилка</measure> <price> 3 . 76 </price> </item> <item> <name>кебапчета</name> <ammount>12</ammount> <measure>брой</measure> <price> 4.20 </price> </item> </order>
  • 17. XML Schemes and Validation
  • 18. Schemes and Validation The XML documents structure is defined by schemes Schemes describes Possible tags Possible attributes Possible values for the attributes and elements Order of the tags Default values
  • 19. The DTD Language DTD ( Document Type Definition ) is : Formal language for describing XML document structures Contains sum of rules for the tags and their attributes in a document Text-based language, but not XML based Rarely used because it is substituted by XSD
  • 20. The DTD Language (2) DTD Example: <!ELEMENT library (book+)> <!ATTLIST library name CDATA #REQUIRED > <!ELEMENT book (title, author, isbn)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT isbn (#PCDATA)>
  • 21. XSD Schemes XSD (XML Scheme Definition Language) is: Powerful XML-based language for describing the structure of XML documents Contains sum of rules for the tags and their attributes is a document XSD schemes have bigger descriptive power than the DTD XSD consequently replaces DTD
  • 22. XSD Scheme Example <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xs:element name=&quot;library&quot;> <xs:complexType> <xs:sequence> <xs:element ref=&quot;book&quot; maxOccurs=&quot;unbounded&quot;/> </xs:sequence> <xs:attribute name=&quot;name&quot; type=&quot;xs:string&quot; use=&quot;optional&quot;/> </xs:complexType> </xs:element> (the example continues)
  • 23. XSD Scheme Example (2) <xs:element name=&quot;book&quot;> <xs:complexType> <xs:sequence> <xs:element ref=&quot;title&quot;/> <xs:element ref=&quot;author&quot;/> <xs:element ref=&quot;isbn&quot;/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name=&quot;title&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;author&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;isbn&quot; type=&quot;xs:string&quot;/> </xs:schema>
  • 24. XPath
  • 25. XPath XPath (XML Path Language) is a language for addressing parts of XML documents XPath expressions contains description of paths to nodes and criteria, which the nodes should pass XPath is frequently used with XSLT and XPointer Example for XPath expressions: /library/book[isbn= ' 1-930110-19-7 ' ] /catalog/cd[ @ price < 10.80]
  • 26. XPath Expressions / – addresses the root element /someNode – addresses all nodes with name &quot; someNode &quot;, direct inheritors to the root /books/book – addresses all nodes &quot; book &quot; , direct inheritors to the node &quot; books &quot; /books/book[price<&quot;10&quot;]/author – addresses all authors ( /books/book/ author ), whose books have price < &quot; 10 &quot; /items/item[@type=&quot;food&quot;] – addresses all nodes with name item , which have attribute &quot; type &quot; with value &quot; food &quot; and are inheritors to the &quot; items &quot; node
  • 27. XSL
  • 28. XSL for Cross - Media Publishing PDF as digital preprint HTML a s standard I nternet F ormat For Online P ublishing Author writes in text processing system using style sheets System saves as/ converts to XML <XML-Document> Catalogue entry MARC-Format Library catalogue XSLT-Stylesheet XSLT-Stylesheet XSLT-Stylesheet
  • 30. What is XSLT? XSLT stands for XSL Transformations XSLT transforms an XML document into another text format document U ses XPath to navigate in the XML document XSLT is a W3C Recommendation
  • 31. XSL/XSLT Capabilities Add prefix or suffix text to content Remove, create, re-order and sort elements Re-use elements elsewhere in the document Transform data between XML formats Specify the XSL formatting objects to be applied to each element class Uses a recursive mechanism to go through document
  • 32. Browsers Support Note: Not all browsers have full support for XML and XSLT Internet Explorer 6 – full support Mozilla 1.7.8 - is available with an XSLT implementation Netscape 8 - based on the Mozilla engine. Same XML / XSLT support as Mozilla Opera 8 - supports XML + CSS
  • 33. Simple XML <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <catalog> <cd> <title> Evergreens </title> <artist></artist> <country>USA</country> <company> USA Music Enterprise </company> <price>1 2 . 0 0</price> <year>198 0 </year> </cd> . . . </catalog> First we have a XML document catalog.xml
  • 34. Create an XSL Style Sheet <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;> <html> <body> <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> Then create an XSL Style Sheet ( cdc.xsl )
  • 35. Link the XSL Style Sheet to the XML Document A XML document can be linked explicitly to a XSL transformation document Use processing instruction <?xml-stylesheet ?> <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;cdc.xsl&quot;?> <catalog> ... </catalog>
  • 36. Output Format Control <xsl:stylesheet xmlns:xsl= . . .> <xsl:output method= &quot; html &quot; encoding= &quot; UTF-8 &quot; … /> <xsl:template match = &quot; / &quot; > <HTML>…</HTML> </xsl:template> </xsl:stylesheet> Define output as XML, HTML, or text Can specify the character encoding Control the XML declaration and DOCTYPE
  • 37. XSLT Specification Available from http://www.w3.org/XSL/ Defines 34 elements and their attributes Can build useful style sheets using stylesheet template apply-templates Depends on the XPath specification
  • 38. Template Element Template element specifies transformation rule The match attribute takes XPath expressions If more than one XPath matches – then use priority rules to determine which is used <xsl:template match=&quot;/&quot;> … </xsl:template>
  • 39. Import Element Use import element to include multiple XSLT files <stylesheet … > < import href=&quot;tables.xsl&quot;/> < import href=&quot;features.xsl&quot;> <template … > … </template> … </stylesheet>
  • 40. The <xsl:value-of> Element U sed to extract the value of an XML element Note: The value of the select attribute is an XPath expression ... <xsl:value-of select=&quot;catalog/cd/title&quot;/> <xsl:value-of select=&quot;catalog/cd/artist&quot;/> ...
  • 41. The <xsl:for-each> Element U sed to select every XML element of a specified node-set (in a loop) Note: The value of the select attribute is an XPath expression ... <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body> ...
  • 42. The <xsl:for-each> Element Filter output We can also filter the output from the XML <xsl:for-each select=&quot;catalog/cd[artist='Bob Dylan ']&quot;> We use expressions in square brackets [ ... ] for setting conditions Legal operator are: =  (equal) != (not equal) &lt; less than &gt; greater than
  • 43. XSLT <xsl:sort> Element U sed to sort the output Add this element inside the <xsl:for-each> element Note: The select attribute indicates what XML element to sort on <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:sort select=&quot;artist&quot;/> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:for-each> </body>
  • 44. Sort Element Properties The ' order ' attribute ' ascending ' or ' descending ' The ' data-type ' attribute ' text ' (default) or ' number ' The ' case-order ' attribute ' lower-first ' or ' upper-first ' <xsl:sort select=&quot; product/price &quot; data-type=&quot;number&quot; order=&quot;descending&quot; />
  • 45. The <xsl:if> Element U sed to put a conditional test against the content of the XML file Note: The value of the required test attribute contains the expression to be evaluated <h2>My CD Collection</h2> <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:if test=&quot;price &gt; 10&quot;> <br/> <xsl:value-of select=&quot;title&quot;/> <xsl:value-of select=&quot;artist&quot;/> </xsl:if> </xsl:for-each> </body>
  • 46. The <xsl:choose> Element U sed in conjunction with <xsl:when> and <xsl:otherwise> t o express multiple conditional tests <xsl:choose> <xsl:when test=&quot;XPath expression &quot;> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose>
  • 47. The <xsl:apply-templates> Element A pplies a template to the current element or to the current element's child nodes S elect attribute – will process only the child element that matches the value of the attribute Note: The value of the required select attribute is a XPath expression <xsl:template match=&quot;cd&quot;> <p> <xsl:apply-templates select=&quot;title&quot;/> </p> </xsl:template> <xsl:template match=&quot;title&quot; > Title: <xsl:value-of select=&quot;.&quot;/> <br /> </xsl:template>
  • 48. Variable Element Variables may be declared and used in XSLT Variable is referenced with $ notation <xsl:variable name=&quot;colour&quot;>red</xsl:variable> <xsl:value-of select=&quot;$colour&quot;/>
  • 49. Reusing Templates If same formatting is required many times // A named template called by call-template <xsl:template name=&quot;CreateHeader&quot; > <html:hr/> <html:h2>***<xsl:apply-templates/>***</html:h2> <html:hr/> </xsl:template> ... <xsl:template match=&quot;title&quot;> < xsl:call-template name=&quot;CreateHeader&quot; /> </xsl:template> <xsl:template match=&quot;head&quot;> < xsl:call-template name=”CreateHeader&quot; /> </xsl:template>
  • 50. Attribute Values Use ' value-of ' element to access attributes Attributes identified by ' @ ' prefix <full-name first=&quot;John&quot; second=&quot;Smith&quot;/> ----------------------------------------- <xsl:template match=&quot;full-name&quot;> <ajr:person> <xsl:value-of select=&quot;@first&quot; > <xsl:value-of select=&quot;@second&quot; > </ajr:person> <ajr:person name=&quot;{@first} {@second}&quot; /> </xsl:template> ----------------------------------------- <ajr:person>John Smith</ajr:person> <ajr:person name=&quot;John Smith&quot;/>
  • 51. Creating Elements Use ' Element ' tag to create new elements Most powerful with use of variables <xsl:template match= &quot; name &quot; > <xsl:element name= &quot; {.}&quot;> Nice person! </xsl:element> </xsl:template> <name>Gosho</name Input <Gosho> Nice person! </Gosho> Result
  • 53. Introduction to XML Questions?
  • 54. Exercises What does the XML language represents ? What is it used for? When do we use it ? Create an XML document students.xml , which contains structured description of students. For each student you should enter information for his name, sex, birth date, phone, course, specialty, faculty number and a list of taken exams (exam name, tutor, grade). What does the namespaces represent in the XML documents? What are they used for? When do we used them?
  • 55. Exercises (2) Add default namespace for the students &quot; urn:students &quot; . Write an XML file containing orders. Each order is described by date, customer name and a list of order items. Each order item consists of product name, amount and price. Write an XSL stylesheet to transform the XML file to a human readable XHTML document. Sort the products in alphabetical order. Test the produced XHTML file in your Web browser.
  • 56. Exercises (3) Write your CV in XML format. It should have the following structure: Personal information (name, DOB, ...) Education Skills Work experience ... Write a XSL stylesheet for transforming the CV to HTML and XML with other structure.

Editor's Notes

  • #2: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #3: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #4: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #14: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #18: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #25: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #28: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #29: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #30: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #31: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ## XSLT is the most important part of XSL. XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree . In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates. When a match is found, XSLT will transform the matching part of the source document into the result document.
  • #32: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #33: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #34: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #35: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #36: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #37: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ## Output Format Control &lt;xsl:output&gt; has a large number of attributes that control the way the result document is produced, including generation of true HTML rather than XHTML output. For an XML document, this feature allows authors fairly explicit control over the contents of the result document XML declaration, the DOCTYPE declaration, use of CDATA sections, and so on. Specifying html for the method causes the XSLT processor to produce conventional HTML as output text instead of XHTML. Specifying text causes the output to consist only of element text content, concatenated together.
  • #38: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #39: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #40: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #41: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #42: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #43: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #44: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #45: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #46: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #47: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #48: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #49: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #50: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #51: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #52: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  • #53: (c) 2007 National Academy for Software Development - http://academy.devbg.org All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##