Skip to Content
XML in a Nutshell, 3rd Edition
book

XML in a Nutshell, 3rd Edition

by Elliotte Rusty Harold, W. Scott Means
September 2004
Intermediate to advanced
712 pages
24h 45m
English
O'Reilly Media, Inc.
Content preview from XML in a Nutshell, 3rd Edition

Abbreviated Syntax

An abbreviated syntax is available for particularly common location steps. In this syntax, five axes may use this shorthand:

.

The context node

..

The parent node

name

The child element or elements with the specified name

//

All descendants of the context node, and the context node itself

@ name

The attribute of the context node with the specified name

Using the abbreviated syntax, the previous examples can be rewritten in the following manner:

set
.//.
ancestor-or-self::*
@xlink:href
set[position( )=2]
.//.[.='Eunice']
ancestor-or-self::*[position( )=2][.="Celeste"]
@xlink:href[starts-with('http')]
ancestor-or-self::*/*[position( )=1]
document/set[position( )=2]/following-sibling::*
.//.[.='Eunice']/@ID
//ship/ancestor-or-self::*/*[position( )=1]
/document/set[position( )=2]/following-sibling::*
/descendant::node( )[.='Eunice']/@ID
set | ./*//vector | ancestor::* | @href

Not all location steps can be rewritten using the abbreviated syntax. In particular, only the child, self, attribute, descendant-or-self, and parent axes can be abbreviated. The remaining axes must be spelled out in full.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XML: Visual QuickStart Guide, Second Edition

XML: Visual QuickStart Guide, Second Edition

Kevin Howard Goldberg
XML Hacks

XML Hacks

Michael Fitzgerald

Publisher Resources

ISBN: 0596007647Errata PageSupplemental Content