370 likes | 525 Views
XML Technology in E-Commerce. Lecture 5 XPath, XLink. Course Announcements. Examination XTEC 2000/2001. The list for registration is available at INF room 5047 (Joke Lammerink). Lecture on June 12 will be in CC3.
E N D
XML Technology in E-Commerce Lecture 5 XPath, XLink
Course Announcements Examination XTEC 2000/2001 The list for registration is available at INF room 5047 (Joke Lammerink). Lecture on June 12 will be in CC3. Additional information can be found in Announcements at URL: http://trese.cs.utwente.nl/courses/xtec
Lecture Outline • XPath • Purpose; • Data Model; • Location Path Syntax; • Location Path Evaluation and Examples; • XLink • HTML Links; • Requirements for Linking; • Extended Link Model; • XML representation; • Simple Links;
Software Application SAX DOM Parser XML Languages XLink XSLT XPointer XML Schema XPath XML Namespaces XML Overview
XPathPurpose • Specifies string-based, non-XML language for expressions; • Addresses parts in XML documents; • Provides functions for manipulation of strings, numbers and booleans; Specification address - http://www.w3.org/TR/xpath(Recommendation since 16 November 1999)
XPathApplications • Specification of patterns of nodes in XML documents (used in XSLT templates); • Specification of points (addresses) in XML documents used as anchors for links (XPointer and XLink); • Querying and extracting parts of XML documents; • XPath expressions can be values of XML attributes; • XPath expressions can be a part of URIs;
Data Model • XML document is modeled as a tree of nodes; • Node types: • root nodes; • element nodes; • text nodes; • attribute nodes; • namespace nodes; • processing instruction nodes; • comment nodes; • Nodes are ordered; • Examples - Deitel 11.2, fig. 11.2, page 300;
XPathExample • Simple DTD: <!ELEMENT book (title, chapter*) > <!ELEMENT chapter (title, section*) > <!ELEMENT section (section | para)* > • Example XPath expression that selects element nodes: child::chapter/descendant::para Selects all paragraphs contained in the chapters of the book (provided that the book is the context node)
Expressions • Expressions are the primary syntactic construct in XPath; • Expression evaluation yields object of one of the following types: • node set; • boolean; • number; • string; • Location path - expression that selects a set of nodes. The result is a node set;
Location path • Example: child::chapter/descendant::para • Evaluation is always made against a particular context node. • The example selects all paragraph elements that have ancestor among the chapter children of the context node: Context node ……. chapter chapter para para para para
Location Path Syntax child::chapter / descendant::para Location path: Location step Location step Location step: child :: para [position()=1] Axis Node test Predicates • Axis: specifies the tree relationship between the context node and the nodes that will be selected by the step; • Node test: specifies the node type to be selected; • Predicate: refines the selection;
Axes • Axes: • self; • parent; • child; • ancestor; • ancestor-or-self; • descendant; • descendant-or-self; • following-sibling; • preceding-sibling; • following; • preceding; • attribute; • namespace; • Axis can be forward or reverse axis. See Deitel 11.3.1, fig. 11.6, page 305.
ancestor ancestor-or-self parent self child descendant descendant-or-self Axes
following-sibling preceding-sibling following preceding Axes
Node Tests • Axes have principal node type: • Attribute type for attribute axis; • Namespace type for namespace axis; • Element type for others; • Node tests: • * - true for any node of the principal node type; • node() - true for any node of any type; • text() - true for any text node; • comment(); • processing-instruction(); • node name, e.g. chapter;
Predicates • Predicates refine the selected node set in a location step; • Predicates are evaluated sequentially from left to right; • Predicates always result in true or false; • Examples: • para[position()=3], para[3]; • para[last()]; • para[id(id_string)]; • para[attribute::type="warning"];
Location Path Evaluation • The starting point is the context node. It is specified through additional, application specific mechanism; • For a given location step and given context node a node set is generated by applying axis information, node test and predicates; • Each node in the resulting node set becomes a context node for the next step. The result is an union of the nodes sets generated for each context node; • Expression value is the node set generated by the last location step;
Location PathAdditional Details • Absolute and relative location path: • relative: child::chapter/descendant::para; • absolute: / child::chapter/descendant::para; • Abbreviated Syntax: • If no axis is specified, child is the default; • attribute::name = @name; • self::node() = . (selects the context node); • parent:: = ..; • /descendant-or-self::node()/ = //; • div/descendant-or-self::node()/child::para = div//para;
Location PathAbbreviation Syntax Examples • */para - selects all para grandchildren of the context node; • //olist/item - selects all item elements that have olist parent element; • ../@lang - selects the lang attribute of the parent of the context node; • para[@type="warning"][5] - selects the fifth para child element of the context node that has type attribute with value “warning”; • para[5] [@type="warning"] - selects the fifth para child of context node if it has attribute type with value “warning”;
XPathSummary • XPath defines syntax for expressions used in other XML specifications (XSLT, XPointer); • XPath defines a tree-like logical model of XML documents; • Location paths are expressions that select a set of nodes; • Software support: MSXML Parser, Apache XML Project, Read: Deitel 11 Assignment: Deitel Ex 11.3, page 316
Lecture Outline • XPath • Purpose; • Data Model; • Location Path Syntax; • Location Path Evaluation and Examples; • XLink • HTML Links; • Requirements for Linking; • Extended Link Model; • XML representation; • Simple Links;
Linking • Linking in the context of WWW: • Link is a relationship between resources; • Resource - any addressable unit of information or service on the Web; • Examples - HTML pages, images, documents, programs (services), database queries; • URIs are used for addressing a resource; • Links are asserted by linking elements; • Example - hyperlinks in HTML;
HTML Links Web Resource Web page • Inline link - the link is embedded in the one end; • Dedicated link element - A element; • Only specific part of the page can be addressed - marked by <A name=“anchor”/> element; • Links have fixed behavior; • Links have only two ends;
Requirements for Linking • Addressing - any element of an XML document must be addressable. Also, document authors must be able to select single character or portion of text; • Relationships between more than two resources; • Any element in an XML document must be able to assert a link; • Attaching external links without resource modification must be possible (so called third party links); • Separation of link semantics from link type; • Support for the basic link semantics (inclusion, expansion);
XLink • Specifies language for link description used in XML documents; • Satisfies the previously formulated requirements; • Provides support for simple links (similar to HTML links) and for more sophisticated links; • Depends on other standard for addressing: XPointer; • Specification address: http://www.w3.org/TR/2000/PR-xlink-20001220/ (Status: proposed recommendation)
XLinkBasic Terms • XLink link is an explicit relationship between resources; • The link is made explicit by a linking element; • Using or following a link is called traversal. It always involves two resources; • Information about how to traverse a pair of resources is called arc; • Local resource - the linking element by itself or a child of the linking element; • Remote resource - addressed by a URI;
XLinkMarkup Design • XLink defines a namespace with URI: http://www.w3.org/1999/xlink • The namespace contains the following attributes: • type, href, role, arcrole, title, show, actuate, label, from, and to; • XLink defines two kinds of links: • Extended; • Simple;
Extended Link Model Arc Locator to remote resource Locator to remote resource Label=“L4” Label=“L3” Extended link Local resource Arc Label=“L5” Label=“L1” Label=“L2” Locator to remote resource Locator to remote resource
Extended LinkXML Representation • Example: link that represents the relationship between student, course and student’s grade; • Representation of the link element: <courseload xmlns:xlink=“http://www.w3.org/1999/xlink” xlink:type=“extended”> ...elements for student, course and grade... …traversal information as arc elements… </courseload>
XML RepresentationExternal Resources • Student and course information are external resources represented by a locator type element: <student xlink:type=“locator” xlink:href=“http://some.site/student007” xlink:label=“student”/> <course xlink:type=“locator” xlink:href=“http://some.site/course6” xlink:label=“course” />
XML RepresentationLocal Resources • Grade information is local resource represented by resource type element: <grade xlink:type=“resource” xlink:label=“grade”>5.5</grade>
XML RepresentationArcs • We can specify two arcs: between the student and the course and the student and his grade <arcEl xlink:type=“arc” xlink:from=“student” xlink:to=“course” xlink:title=“partcipates”/> <arcEl xlink:type=“arc” xlink:from=“student” xlink:to=“grade” xlink:title=“has grade”/>
XML RepresentationOther XLink Attributes • Semantic attributes: • role: can be applied to extended, locator and resource type elements. It asserts a property that describes the semantics of the resource. The value is URI; • arcrole: used on arc type elements; • title: provides human readable information; <arcEl xlink:type=“arc” xlink:from=“student” xlink:to=“grade” xlink:arcrole=“http://some.site/arcinfo.xml” xlink:title=“student’s grade”/>
Simple Links • Simple links can be perceived as a special kind of extended link, with some limitations imposed: • associates exactly two resources: one local and one remote; • specifies an arc from local to remote resource; • provides a short syntax for the equivalent extended link; <student xlink:type=“simple” xlink:href=“http://some.site.com/student.html”> John Smith </student>
Behavioral Attributes • Describe the intended behavior for simple and arc type elements; • show attribute: • Specifies the desired presentation of the ending resource; • Values: new, replace, embed, other, none; • actuate attribute: • Specifies the desired timing of traversal; • Values: onLoad, onRequest, other, none;
XLink and DTDs • In XLink linking elements are asserted via a set of attributes; • The syntax is rather verbose, a large set of attributes must be specified; • DTD can be used to provide default and fixed values for attributes. Attributes can be omitted in instance documents; • See Deitel 14.3;
XLinkSummary • XLink provides powerful mechanism for links definition in XML documents: • Multi-ended, third party links with additional meta information through extended link type; • HTML like links through simple link type • XLink depends on XPointer as a mechanism for addressing elements and points in XML documents; Read: Deitel 14.1-14.3, skip 14.4-14.6 Assignment: Deitel Ex 14.3, page 394. For some hints see the course web site.