ITWissen.info - Tech know how online

XML Pointer Language (XPointer)

XPointer (XML Pointer Language) is a query language for extending the addressing capabilities of XPath. XPointer thus builds on the XPath specification and was also developed by the World Wide Web Consortium (W3C). With the help of XPointer, individual elements in external documents can be unmasked on the basis of XPath expressions and correspondingly extended URI references. Uniform Resource Identifiers (URI) are character strings used to uniquely identify Web resources. XPointer supports different forms of addressing fragments in external documents. XPointer can select an element to identify based on its type, name, or number, as well as its relationship to other elements.

The XPointer language is specified by the W3C through a basic terminology-defining framework and two schemas based on it. XPointers are references - i.e. pointers to fragments within an XML document. This mechanism is based on an extension of XPath with corresponding URI references. Thus, the reference can refer to certain segments of a document without knowing the document as a whole. For example, with XLink there is an implementation that uses XPointer.

XPath for accessing XML documents

The function of XPath is to access nodes within the node tree in the context of a single XML document. XPointers can now be used beyond this framework to do this, and specify fragments of a document as targets of a link or for other purposes. An example is the link with XLink, where only the required information can be filtered by using XPointers. Here, the separate labeling of fragments as in HTML, for example - where special fragment identifiers are expected - is not necessary with XPointers. Instead, the fragment identifiers are represented here by the compound XPath expressions for filtering the required information. XPointers can be used for all resources of the following media types:

text/xml, application/xml, xml-external-parsed-entity, application/xml-external-parsed-entity.

When formulating an XPointer expression, a distinction is made between the so-called shorthand and a pointer based on a schema. The shorthand pointer directly contains the name of the information to be filtered such as:

(id("content"))

This also shows that an XPointer is always appended to a reference with a hash sign (#) as a separator.

For pointers based on a schema, the corresponding name of the schema is prepended in each case - either element() or xmlns(). Supported by the framework, the developer can also define his own schemas. The name of the schema is always followed by the bracketed expression that refers to the information to be filtered. For example

element(content/3), navigates from the element (=content) to its 3rd child element

So the element() schema can be used to reference a single element within an XML document. The schema xmlns() allows namespaces to be assigned to information units, thus avoiding ambiguities of references - also called addressing. This pointer does not reference any information itself. Instead, the pointer enables a subsequent pointer to specify its reference with the help of the previously defined namespace, for example

xmlns(a=hhtp://imweb.de/content), first assigns a namespace with the prefix "a".

xmlns(a=hhtp://imweb.com/content)#xpointer(/a:location), then use the following pointer to directly select an element from the namespace.

XPointer supports several mechanisms of addressing parts of a document - simple names, so-called child sequences, points and ranges. This allows specific referencing of either an element or entire fragments. These addressed locations are also called points. These points are located on a level below a node - this provides a finer structure of the referenced document. For example, string comparisons are used to filter information in documents or web sites.

Informationen zum Artikel
Englisch: XML Pointer Language - XPointer
Updated at: 29.10.2013
#Words: 1009
Links:
Translations: DE