Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

XML Path

..
,

lizorkin@ispras.ru

XPath  XML-.
Scheme
XML- SXML XML-.
SXML  XML-
S-  ,
XPath SXML-.
, XPath ,

. .
XPath
SXML-, .
1

XML Path (XPath) [1], , 


XML-. XPath
XML
XML-; , XSLT, XPointer XQuery.
XML
, XML-
.

(, XPath Java) ,
(impedance mismatch) [2].
XML
XML- .
SXML  XML S- [3].
Scheme S-
, ,
XML-. Scheme [4]  ,
, - [5]. Scheme
SXML-,
XML
.
XPath
XML- [1].
, , XML-,

XML-.
XPath  parent, ancestor , 
1

,
. XPath [1] (, ,
XML [6])  ,
. SXML S , S-
, [7].
, SXML
XML XPath. , SXPath 
XPath SXML 

XPath,
SXML.
, XPath ,
.
, XPath SXML , .

Scheme SXPath.
SXPath SXML-
XPath, .
,
SXML,

. ,
XPath ,
,
,
.
, ,
XPath 1.0, XPath 2.0 [8],

.
. 2 ,
. 3
. 4
.
5. 6 ;
7. 8.
9 .
2

,
. XPath; SXML
SXPath ,
XPath.
2.1

XPath

XPath  XML-. ,
XML- , , , XPath [1]
.
(expr),
.

. :
2

/child::doc/child::chapter[position()=5]/child::section[position()=2]
. 1: , 2- (section) 5- (chapter)
doc.

( );
;
XPath [9];
, .
, (expr) XPath,
(location path) [1].
, (node-set) [9],
(, ) ,
. , ,
XML-.
(location step),
("/").
3 :

(axis), ,
, , .
" " , XML- [10].
XPath 13 . ,
, ..
("::").
(node test), , , ,
. " ",
, .
(predicates).
,
.
.
, , XML-.
,
, . ,
 XML-.
XPath . 1. 3
, 2 .
, , . 1 2-
(section) 5- (chapter) doc.
2.2

SXML

SXML XML
XML Infoset [6].
XML SGML
XML .

3

<?xml version='1.0'?>
<doc>
<tag attr1="value1" attr2="value2">
<nested>Text node</nested>
</tag>
<empty/>
</doc>

(*TOP* (*PI* xml "version='1.0'")


(doc
(tag (@ (attr1 "value1") (attr2 "value2"))
(nested "Text node")
)
(empty)
))

. 2: XML- ( ) SXML.
(     XML)
[5].
SXML
XML S- Scheme.

.
XML S-,
(    ),
,
SXML [11].
XML- SXML . 2,
XML SXML.
SXML [2].
2.3

SXPath

SXPath  XPath Scheme,


SXML. SXPath
.

, [12].

.
SXPath , ,
; ,
.
:

, .

.
SXPath .
XPath, ,
XPath .
SXPath
,
Scheme.
SXML- .
SXPath , ,

, SXPath [12].

, ,
, XPath ,
Scheme [3].
3

[7],
, SXML
XML [6].

SXML XPath.
[7] , , XPath
, .
,
() SXML.
SXML , ,
.
x :
parent(x) = {y|y = child*(root), x = child(y)} ,
child* child, root
SXML-.


,
. , SXPath
.
, , SXPath
.
[7] 3
SXML-.
,
3- ,
XML- S-.
SXML 
.
, , SXML,
. [7],
.
XPath,
, SXML.
SXML , ,
XPath,
.
[13] , ,
XPath ,
. [13] XPath,
SXML
. ,
XPath ,
XPath 1.0.
, [13], ,
XPath ,
[7].
5

XPath
.
4

,
XPath.

1 XPath:
/doc/head/../body
(location path) 4
:
, doc.
2- head.
3- head.
body 1 .
, 3- parent [8]
( XPath ). ,
SXML ,
SXML , ,
,
.
,
1,
:

, , , doc.
, 2- , head,
- , 3-
, , 2-
. , : 2-
head,
, parent .
, parent 3-
.
: body.
1, ,

.

XPath.
1

XPath , .

XPath,

, XPath
,
.
, ,
XPath. ,
, .

, .
, XPath
, .

1 XPath XML-,
, ,
, .

1 .

XPath ,
, ..
.
XML Infoset [6], XML-
,
.

, ,
,
; . .
t
u

XML, ,
(Document Object Model, DOM),
-, .. ,
.
,
. ,

.
XPath
XPath.
( parent, ancestor, preceding .)

. ,
, ,
2 . , (,
child, descendant), , ,
(
). ,
, .
XPath

.
,
2

,
XPath, . ,
XPath.
, XPath
;
, XML-.
5.1

, ,
, .

1  +:
ancestors_number = 0, 1, 2, . . . , + .
, XPath
{node1 , node2 , . . . , noden },
node1  ;
nodek+1  nodek , k = 1, n 1;
n < ancestors_number noden  XML-, n =
ancestors_number.
, +
.
,
XPath (
). ,
,
3 .
XPath XPath.
,
, (location path) (location step).
, XPath
:
XPath,  .
XPath ,
,
XPath.
,
XPath .
,
XPath , ..
.
, XPath
,
XML. XPath XPath
, ,
,
.
3

XPath ,

, XPath.

2 ,
XPath , N , ,

, , ,
N .

3 ,
, M , , ,

, ,
M .
N ,
.
,
:
XPath_grammar_rule(required_ancestors_number) = requires_ancestors_number ,

XPath,
;
, ;
,
(
3).
,
,
,
XPath .

2
XPath child, 2
(.. ). child
, ,
child . ,
child :
,
;
- ,
, ,
..

, child, ,
( -),
,
. ,
, child,
, 1 , ,
. ,
:
Child(ancestors_number) = ancestors_number 1 ,
: Child(2) = 1 .
9

, XPath

, XPath.
(axis specier),

XPath.
, +,
:

+ C = +,

C 6= ;

max(+, C) = + .
5.2

, ,
0, , ,
XPath.
1. (location path)
.
LocationPath ::= Step1 /Step2 / . . . /Stepn1 /Stepn
,
, .
, .
, , ,
, ,
. :
LocationPath(ancestors_number) = Step1 (Step2 (. . . (Stepn1 (Stepn (ancestors_number))) . . .)) .
,
,
, .
2. (location step) .
(node test), , ,
.
Step ::= AxisSpecier NodeTest Predicate1 . . . Predicatem

, .
- ,
, .. - ,
. ,
,
, ,
.
:
Step(ancestors_number) = AxisSpecier(max(ancestors_number; max (Predicatei (0)))) .
i=1,m

10

3. (axis specier)  XPath,


.
, (,
, ),
,
, XPath.

5.3, ,
:
Ancestor(ancestors_number)
Ancestor-or-self(ancestors_number)
Attribute(ancestors_number)
Child(ancestors_number)
Descendant(ancestors_number)
Descendant-or-self(ancestors_number)
Following(ancestors_number)
Following-sibling(ancestors_number)
Namespace(ancestors_number)
Parent(ancestors_number)
Preceding(ancestors_number)
Preceding-sibling(ancestors_number)
Self(ancestors_number)

=
=
=
=
=
=
=
=
=
=
=
=
=

+ ;
+ ;
max(ancestors_number 1;
max(ancestors_number 1;
max(ancestors_number 1;
ancestors_number ;
+ ;
max(ancestors_number; 1)
max(ancestors_number 1;
ancestors_number + 1 ;
+ ;
max(ancestors_number; 1)
ancestors_number .

0) ;
0) ;
0) ;

;
0) ;

4. (predicate) XPath .
(expr),
,
,
.
,
XPath,
, ,
XPath [1].
5. (union expression)
, .
,
:
UnionExpr ::= PathExpr1 | . . . |PathExprk ;
UnionExpr(ancestors_number) = max (PathExpri (ancestors_number)) .
i=1,k

6. (path expression)
PathExpr ::= FilterExpr/Step1 /Step2 / . . . /Stepn ;
, ,
:
PathExpr(ancestors_number) = FilterExpr(Step1 (Step2 (. . . (Stepn (ancestors_number)) . . .))) .

11

(lter expression)
.
FilterExpr ::= PrimaryExpr Predicate1 . . . Predicatep ;
FilterExpr(ancestors_number) = PrimaryExpr(max(ancestors_number; max (Predicatei (0)))) .
i=1,p

7. (primary expression), ,
, .. .

, ,
( ),
.
,
XPath [9],
, .
lang, ,
id, ,
XPath.
5.3

XPath
.

1 XPath

XPath
, XPath
,
.

2 2 .

, XPath.
,
XPath
, .
1. XPath ,
.
parent ,

, , 1.
ancestor ancestor-or-self
( ancestor-or-self ).
XPath
,
5.1 , +.
child, descendant, attribute namespace ,
1;

. , ,
( descendant  )
; ,
, 1
, .
12

self descendant-or-self ,
,
, .
following-sibling preceding-sibling ,
XML- SXML,
-,
() .
,
, ,
1.
following preceding ,
+, XML-,
( preceding  )
, .

2. ,
XPath
. ,
XPath
, ,
XPath, .
,
XPath, ,
(.. ),
.

XPath . , , ,
(location steps) (location path)
, ,
, .

XPath ,
, .
, XPath,
,
XPath
.
t
u

2
XPath  .

3
XPath XPath
, .

/descendant::tr[parent::table]
tr,
table 4 . , descendant
4

, -,
, .

13

, 1,
parent,
.
.

.
6

,
XPath.
6.1

 ,
, ,
.
, Scheme,
XPath.
5 XPath
SXML-
XPath ,
.
. 3,
XML-, SXML. ,
S-
-, . 3 ,
. ,
XPath,
, . 3 . ,
,
( . 3
).
, , ,
XPath , . 3
, ,
 .
( . 3 ) XPath
, ,
, XPath
.
,
XPath ,
,
.
6.2

XPath ,
XQuery XSLT.
XPath
XML XML-.
XPath
XML- , XML-
14




?



?
?


?







?
?


?







?




?


?






?



?
?







?

?
?





?
?
?









. 3: XML-,
XPath. , 
.
XQuery [14], XPath ,
, XQuery .
XQuery
(node identity). XML, XQuery.
,
.
,
N ,
, N,
. , N
, XQuery
,
, .

, .

XML
XPath. Scheme
SXML- ,
,
, ,
.
XPath
,
,
.
15

, ,
XPath
,
, ,
.
6.3

XPath
XML- [15], XPath
XML-
. XPath
, - (serializable) XPath XML-.
[16] ,
, XML-,
. [16]
,
,

.
(tree-locking
protocol). [16].
1. , ,
.
2. ,
, .
3. .
4.
 ,
.
,
[16] , ,
 XML  4

, .
,
XPath. ,

.  
, -.
5, XPath
,
, , ,
, .
XPath, ,

XML-
.

16

XPath
, .
XPath (
XPath ):

ancestor::*[position()<3]
, XPath [1]
, 3; .., ,
. ,
, , 2,
, , 2, .
XPath
, . ,
ancestor, ,
.
,
.
,
,
XPath.
 XPath, 

.
8

XPath
SXPath,
SXML-.
,
XPath,
. SXPath  ,
XPath
, SXPath, XPath
.
SXML-
,
. SXML-
4 . 4. .
2 ,
.. .
, .
XPath
, .
XPath, node(), * text(),
. ,
4 , . 5.
6 7

, 3 4 .
SXML-,
. ,
.
17

(*TOP*
(elem1
(elem2
(elem3 (elem4 "text5") (elem6 "text7") "text8")
(elem9 (elem10 "text11") (elem12 "text13") "text14")
"text15")
(elem16
(elem17 (elem18 "text19") (elem20 "text21") "text22")
(elem23 (elem24 "text25") (elem26 "text27") "text28")
"text29")
"text30"))
. 4: SXML- 4.

descendant::*/following-sibling::node()/self::text()/parent::*
. 5: , 4 .
SXPath,
XPath
, SXPath, XPath
. 6 7
, ( 20 )
. ,
, .
, XPath
,
,
.
, .. .
,
XPath, ,
, 5
XPath,

4
5
6
7
8
9
10

,



0.004
0.003
0.055
0.010
0.105
0.020
0.303
0.049
1.870
0.632
10.862
3.874
25.008
8.503

. 6: XPath, 3 .

18

4
5
6
7
8
9
10

,



0.022
0.012
0.094
0.020
0.145
0.027
0.552
0.066
17.465
3.992
29.642
6.987
128.570
33.958

. 7: XPath, 4 .

.
9

XPath
SXML
.
,
SXML-,
XPath. XPath
. ,
 , 
.
XPath, XPath
, .
, XPath
,
.
,
XPath
.
.
, ,
XPath
SXML-
XPath .
SXML
XPath , SXML
XML.

[1] J. Clark S. DeRose (). XML Path (XPath) 1.0. W3C


16 1999.
http://citforum.ru/internet/xpath/index.shtml
[2] .. .. SXML: XML- S-.
, 2003, 6, 2.
http://www.elbib.ru/index.phtml?page=elbib/rus/journal/2003/part2/LK

19

[3] O. Kiselyov and K. Lisovsky. XML, XPath, XSLT Implementation as SXML, SXPath and SXSLT.
International Lisp Conference ILC 2002, San Francisco. October, 2002.
http://www.okmij.org/ftp/papers/SXs.pdf
[4] R. Kelsey, W. Clinger and J. Rees (editors). Revised5 Report on the Algorithmic Language Scheme.
Higher-Order and Symbolic Computation, Vol. 11, No. 1, August 1998, and ACM SIGPLAN Notices,
Vol. 33, No. 9, September 1998.
http://www.schemers.org/Documents/ Standards/R5RS/r5rs.pdf
[5] . . XML- Scheme. ,
28, 4, 2002.
http://www.maik.rssi.ru/journals/procom.htm
[6] J. Cowan and R. Tobin (editors). XML Information Set (Second Edition). W3C Recommendation 4
February 2004.
http://www.w3.org/TR/xml-infoset/
[7] O. Kiselyov. On parent pointers in SXML trees.
http://www.okmij.org/ftp/Scheme/parent-pointers.txt
[8] A. Berglund, S. Boag, D. Chamberlin, M. F. Fernandez, M. Kay, J. Robie and J. Simeon (editors).
XML Path Language (XPath) 2.0 W3C Working Draft 23 July 2004.
http://www.w3.org/TR/2004/WD-xpath20-20040723
[9] .. XML. 4 (25-11-2003).
http://www.elbib.ru/index.phtml?page=elbib/rus/methodology/xmlbase/glossary_XML
[10] .. .. XML Path (XPath)
SXPath. , 2003, 6, 4.
http://www.elbib.ru/index.phtml?page=elbib/rus/journal/2003/part4/LL
[11] O. Kiselyov. SXML, revision 3.0, March 12, 2004.
http://okmij.org/ftp/Scheme/SXML.html
[12] K. Lisovsky. STX: Scheme-enabled XSLT processor.
http://www.pair.com/lisovsky/transform/stx/
[13] D. Olteanu, H. Meuss, T. Furche and F. Bry. XPath: Looking Forward. Proc. of the EDBT Workshop
on XML Data Management (XMLDM), 2002.
http://www.csd.uch.gr/ hy561/Papers/looking_forward.pdf
[14] S. Boag, D. Chamberlin, M. Fernandez, D. Florescu, J. Robie and J. Simeon (editors). XQuery 1.0:
An XML Query Language. W3C Working Draft, 12 November 2003.
http://www.w3.org/TR/2003/WD-xquery-20031112/
[15] P. Lehti. Design and Implementation of a Data Manipulation Processor for a XML Query Language.
Ph.D. thesis. Technische Universitat Darmstadt, August 2001.
http://www.ipsi.fraunhofer.de/ lehti/
[16] -, . . .
. . .  , "", 2003. ISBN 5-8459-0384-X
(.)

20

You might also like