![]() |
|||||||||||
ConceptsXCentric is a logic programming language specialized in XML processing (its syntax is similar to Prolog). Its central features are:
Unification and Pattern MatchingThis approach can be explained with a simple example, consider the following simple XML document representing an address book: the resulting term (internal representation) is:
Using this internal representation one can use the unification on a domain of trees with an arbitrary number of leaf nodes to retrieve important data. Consider the following example, if we want the names of every person living in New York we can simply do: Pattern MatchingIn a similar way the user can use pattern matching (provided by operator =~=). In this case one of the arguments must be fully instantiated. This approach is more efficient but doesn't allow the dynamic creation of a new term where some of the variables are not instantiated.Also we provide three predicates that use pattern matching and allow the programmer to find a sequence of elements, find the nth occurrence of a particular sequence of elements and count the number of occurrences of a sequence of elements. The predicates are deep/2, deepp/3 and deepc/3. For example consider we want to find a sequence of elements between two elements named incision in the XML file translated to a term and stored in variable O. We can do: deep(<incision(_),Critical,incision(_)>,O).The sequence we pretend is stored in variable Critical. If we want to find the text of the third occurrence occurrence of element author in document Bib we can simply do: deepp(author(_,T),Bib,3).Variable T will
store the value we pretend. If we want to count the number of
occurrences of author elements in document Book we can simply do:deepc(author(_),Book,C).Variable C will store the number of occurrences of author elements. Note that any of these predicates accepts elements and sequences of elements. Type systemThe programmer can declare types and use them along the program in order to ensure that the data manipulated is in the correct form. This feature is optional; if you don't want you don't need to use types.Type DeclarationsNow, the programmer can add type declarations to programs in order to impose constraints over the data values it processes. Type declarations in Typed XCentric are Regular Expression Types and include a notation for several kinds of values (*,+,?,| and ,). The following table describes Regular Expression Types:
The | operator is implemented by the ';'. For example, a|b is written a;b. Types are associated with sequence variables by means of the operator ::. For example X::t means that sequence variable X only unifies with values of type t. Example 1. A sequence of two or more authors: :- type ta --->
(author([],string),author([],string),author([],string)*).Example 2. Given an XML file with names and authors of books. Get all the names of books with two or more authors (type ta is the same as declared in example 1): process(N):-Here we are searching books that, after the name element have a sequence (that unifies with X) with type ta. The result is: N = Practical Cryptography
Comparing XCentric with the usual list processing approachXCentric improves XML processing avoiding the traditional list processing. Consider we have a document containing books and need to get the names of all books with 2 or more authors, we can use the following XCentric program::- type type_a --->
(author(string),author(string),author(string)*).To do the same thing using only SWI-Prolog (which has a quite good library for processing XML in Prolog): pbib([element(_,_,L)]):-Basic XML Schema SupportXCentric also provides a basic XML Schema support:
Builtins for XML handlingThere are four ways to load HTML/XML data:
|
|||||||||||