View
231
Download
1
Category
Tags:
Preview:
Citation preview
Multi Platform ApplicationsMulti Platform Applications
XML, XPath, XSLT transformXML, XPath, XSLT transform
This WeekThis Week
XPATH – way of breaking down XML docsXPATH – way of breaking down XML docs
XML-FO – a method to format docsXML-FO – a method to format docs
XSLT – A simpler method of formatting docsXSLT – A simpler method of formatting docs
XPATHXPATH
Used to break down the structure of a XML Used to break down the structure of a XML doc and reference sectionsdoc and reference sections
The nodes of an XML document can be The nodes of an XML document can be treated as parts of a document treetreated as parts of a document tree
Nodes of an XML Nodes of an XML docdoc
document (root) nodesdocument (root) nodes
comment, comment,
processing-instruction, processing-instruction,
namespace, namespace,
text, text,
attribute, attribute,
element, element,
XML nodesXML nodes
<message><message><mail> <mail>
<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>
</mail></mail></message></message>
Node
XML relationships - XML relationships - childrenchildren
<message><message><mail> <mail>
<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>
</mail></mail></message></message>
Children of the message object
XML relationships – XML relationships – parent and siblingsparent and siblings
<message><message><mail> <mail>
<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>
</mail></mail></message></message>
Parent of the to,from, heading etc objects
These four items are siblings (same parent)
XML relationships - XML relationships - ancestorsancestors
<message><message><mail> <mail>
<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>
</mail></mail></message></message>
Ancestors of the “to” object are the mail and message object
XML relationships - XML relationships - descendantsdescendants
<message><message><mail> <mail>
<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>
</mail></mail></message></message>
Al these are descendants of the message object
XPathXPath
Methods of selecting nodesMethods of selecting nodes
Selecting NodesSelecting Nodes
ExpressionExpression DescriptionDescription
nodenamenodename Selects all child nodes of the named nodeSelects all child nodes of the named node
// Selects from the root nodeSelects from the root node
//// Selects nodes in the document that matches Selects nodes in the document that matches the named node in the documentthe named node in the document
.. Selects the current nodeSelects the current node
.... Selects the parent of the current nodeSelects the parent of the current node
@@ Selects attributesSelects attributes
XPath addressingXPath addressing
For exampleFor example
to – to – will highlight all items called towill highlight all items called to
/message – /message – will select all items under that will select all items under that elementelement
//body//body – will select all items in the document – will select all items in the document of that nameof that name
ExpressionsExpressions
Path Expression Result
/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 35.00
/mail/subject[ID>5]/priority Selects all the title elements of the subject elements of the mail element that have an ID element with a value greater than 5
WildcardsWildcards
• * - Matches any element node* - Matches any element node• @* - Matches any attribute node@* - Matches any attribute node• node() -- Matches any node of any kindnode() -- Matches any node of any kind
Further ReadingFurther Reading
Look into Xpath Axes and Xpath Location Look into Xpath Axes and Xpath Location pathspaths
You can also see the operators available at You can also see the operators available at http://www.w3.org/TR/2005/WD-xpath-funhttp://www.w3.org/TR/2005/WD-xpath-functions-20050404/#op.numericctions-20050404/#op.numeric
Or Or http://www.w3schools.com/xpath/xpath_fuhttp://www.w3schools.com/xpath/xpath_functions.aspnctions.asp
XLink and XpointerXLink and Xpointer
XLink - XML Linking Language XLink - XML Linking Language
XLink is a language for creating hyperlinks XLink is a language for creating hyperlinks in XML documents in XML documents
XLink is similar to HTML links - but more XLink is similar to HTML links - but more powerful powerful
Not limited to images and text - any element Not limited to images and text - any element in an XML document can behave as an in an XML document can behave as an XLink XLink
Xlinks 2Xlinks 2
XLink has two grouping of linksXLink has two grouping of links
simple links (like HTML) and simple links (like HTML) and
extended links (for linking multiple extended links (for linking multiple resources) resources)
With XLink, the links can be defined With XLink, the links can be defined externally to the linked resourcesexternally to the linked resources
XLink is a W3C StandardXLink is a W3C Standard
XPointerXPointer
XPointer - XML Pointer Language XPointer - XML Pointer Language
XPointer allows hyperlinking to specific parts XPointer allows hyperlinking to specific parts of an XML document of an XML document
XPointer uses XPath expressions to XPointer uses XPath expressions to navigate the position in an XML document navigate the position in an XML document
XPointer is a W3C Standard XPointer is a W3C Standard
Simple XlinkSimple Xlink
<?xml version="1.0"?> <?xml version="1.0"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink"> <homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple" <homepage xlink:type="simple" xlink:href="http://www.bolton.ac.uk">Visit Bolton</homepage> xlink:href="http://www.bolton.ac.uk">Visit Bolton</homepage>
<homepage xlink:type="simple" <homepage xlink:type="simple" xlink:href="http://www.bbc.co.uk">BBC</homepage> xlink:href="http://www.bbc.co.uk">BBC</homepage>
</homepages> </homepages>
Pointing with PathsPointing with Paths
Remember the CD catalog exampleRemember the CD catalog example
How would we pick out an artist from that How would we pick out an artist from that XML file?XML file?
We can point not just to a file but to an area We can point not just to a file but to an area of a file e.g.of a file e.g.
href="http://www.bolton.ac.uk/href="http://www.bolton.ac.uk/catalog.xml#disc(‘Hits').child(1,item)" catalog.xml#disc(‘Hits').child(1,item)"
XMLXML
<?xml version="1.0" encoding="ISO-8859-1"?><?xml version="1.0" encoding="ISO-8859-1"?><collection><collection> <disc <disc title = “Hits” id = “Hits“>title = “Hits” id = “Hits“> <artist>Five</artist><artist>Five</artist> <country>UK</country><country>UK</country> <company>Telstar</company><company>Telstar</company> <price>4.99</price><price>4.99</price> <year>2003</year><year>2003</year> </disc></disc>....</collection></collection>
Xpointer and linksXpointer and links
xlink:href="http://www.bolton.ac.uk/xlink:href="http://www.bolton.ac.uk/catalog.xml#xpointer(id(‘Hits'))"catalog.xml#xpointer(id(‘Hits'))"
You can use a shorter version when linking You can use a shorter version when linking to an element with an id tag. You can use to an element with an id tag. You can use the value of the id directly, like this: the value of the id directly, like this: http://www.bolton.ac.uk/catalog.xml#Hithttp://www.bolton.ac.uk/catalog.xml#Hits"s"
Useful LinksUseful Links
http--http--www.topxml.com-tutorials-sqlxml-sqlxml.pwww.topxml.com-tutorials-sqlxml-sqlxml.pdfdf
SQL Server 2000 and XML Part 6 - AnnotatSQL Server 2000 and XML Part 6 - Annotated XDR Schemes Free Tutorial ed XDR Schemes Free Tutorial
Beginners.co.ukBeginners.co.uk
Recommended