Multi Platform Applications XML, XPath, XSLT transform
This Week XPATH – way of breaking down XML docs XML-FO – a method to format docs XSLT – A simpler method of formatting docs
XPATH Used to break down the structure of a XML doc and reference sections The nodes of an XML document can be treated as parts of a document tree
Nodes of an XML doc document (root) nodes comment,processing-instruction,namespace,text,attribute,element,
XML nodes <message><mail><to>Patrick</to><from>Mick</from><heading>Meeting</heading> Don't forget we need to meet tonight Don't forget we need to meet tonight </mail></message> Node
XML relationships - children <message><mail><to>Patrick</to><from>Mick</from><heading>Meeting</heading> Don't forget we need to meet tonight Don't forget we need to meet tonight </mail></message> Children of the message object
XML relationships – parent and siblings <message><mail><to>Patrick</to><from>Mick</from><heading>Meeting</heading> Don't forget we need to meet tonight Don't forget we need to meet tonight </mail></message> Parent of the to,from, heading etc objects These four items are siblings (same parent)
XML relationships - ancestors <message><mail><to>Patrick</to><from>Mick</from><heading>Meeting</heading> Don't forget we need to meet tonight Don't forget we need to meet tonight </mail></message> Ancestors of the “to” object are the mail and message object
XML relationships - descendants <message><mail><to>Patrick</to><from>Mick</from><heading>Meeting</heading> Don't forget we need to meet tonight Don't forget we need to meet tonight </mail></message> Al these are descendants of the message object
XPath Methods of selecting nodes
Selecting Nodes ExpressionDescription nodename Selects all child nodes of the named node / Selects from the root node // Selects nodes in the document that matches the named node in the document. Selects the current node.. Selects the parent of the current Selects attributes
XPath addressing For example to – will highlight all items called to /message – will select all items under that element //body – will select all items in the document of that name
Expressions Path ExpressionResult /mail/subject[1]Selects the first subject element that is the child of the mail element /mail/subject[last()]Selects the last subject element that is the child of the mail element /mail/subject[last()-1]Selects the last but one subject element that is the child of the mail element /mail/subject[position()<3]Selects the first two subject elements that are children of the mail element /mail/subject[ID>5]Selects all the subject elements of the mail element that have a ID element with a value greater than /mail/subject[ID>5]/priorit y Selects all the title elements of the subject elements of the mail element that have an ID element with a value greater than 5
Wildcards * - Matches any element node * - Matches any element - Matches any attribute - Matches any attribute node node() -- Matches any node of any kind node() -- Matches any node of any kind
Further Reading Look into Xpath Axes and Xpath Location paths You can also see the operators available at functions /#op.numeric functions /#op.numeric functions /#op.numeric Or nctions.asp nctions.asp nctions.asp
XLink and Xpointer XLink - XML Linking Language XLink is a language for creating hyperlinks in XML documents XLink is similar to HTML links - but more powerful Not limited to images and text - any element in an XML document can behave as an XLink
Xlinks 2 XLink has two grouping of links simple links (like HTML) and extended links (for linking multiple resources) With XLink, the links can be defined externally to the linked resources XLink is a W3C Standard
XPointer XPointer - XML Pointer Language XPointer allows hyperlinking to specific parts of an XML document XPointer uses XPath expressions to navigate the position in an XML document XPointer is a W3C Standard
Simple Xlink Visit Bolton Visit Bolton BBC BBC </homepages>
Pointing with Paths Remember the CD catalog example How would we pick out an artist from that XML file? We can point not just to a file but to an area of a file e.g. href=" sc(‘Hits').child(1,item)"
XML <collection> Five Five UK UK Telstar Telstar </collection>
Xpointer and links xlink:href=" og.xml#xpointer(id(‘Hits'))" You can use a shorter version when linking to an element with an id tag. You can use the value of the id directly, like this: s"
Useful Links http-- sqlxml.pdf http-- sqlxml.pdf SQL Server 2000 and XML Part 6 - Annotated XDR Schemes Free Tutorial Beginners.co.uk SQL Server 2000 and XML Part 6 - Annotated XDR Schemes Free Tutorial Beginners.co.uk