1xmltree(3am) GNU Awk Extension Modules xmltree(3am)
2
3
4
6 xmltree - Provides DOM-like facilities to gawk-xml. Its status is
7 experimental. May change in the future.
8
10 @include "xmltree"
11
12 XmlPrintElementStart(index)
13 XmlPrintElementEnd(index)
14 XmlPrintNodeText(index)
15
16 XmlPrintNodeTree(index)
17
18 n = XmlGetNodes(rootnode, path, nodeset)
19 value = XmlGetValue(rootnode, path)
20
22 The xmltree awk library adds DOM-like facilities to the gawk-xml exten‐
23 sion.
24
25 Automatic storage of the element tree
26 The xmlbase library contains rules that automatically store the docu‐
27 ment's element tree in memory. The tree contains a node for each:
28
29 · Element
30
31 · Attribute
32
33 · Text content fragment
34
35 Each node in the tree can be referenced by an integer node index. The
36 root element node has an index of 1. Nodes are stored in lexicographi‐
37 cal order.
38
39 Processing the tree in the END clause
40 The stored tree is not fully available until the end of the input file.
41 The intended way of using the tree is to put all the processing code in
42 the END clause.
43
44 Printing tree fragments
45 XmlPrintElementStart(index)
46 Prints the element's start tag, including the attributes. The
47 index argument must point to an element node.
48
49 XmlPrintElementEnd(index)
50 Prints the element's end tag. The index argument must point to
51 an element node.
52
53 XmlPrintNodeText(index)
54 Prints the text content of the node. The index argument must
55 point to an attribute or text fragment node.
56
57 Selecting tree fragments
58 The xmltree library provides an XPath-like facility for querying or
59 navigating the document tree.
60
61 n = XmlGetNodes(rootnode, path, nodeset)
62 Populates de nodeset integer array argument with the indexes of
63 the nodes selected from the starting rootnode by the given path
64 pattern. Returns the number of selected nodes.
65
66 value = XmlGetValue(rootnode, path)
67 Returns the text content of the set of nodes selected from the
68 starting rootnode by the given path pattern. The content depends
69 on the node kind:
70
71 Attribute node
72 The content is the attribute value.
73
74 Text fragment node
75 The content is the text fragment.
76
77 Element node
78 Concatenates the content of the descendant element and
79 text fragment nodes. Attributes are excluded from the
80 result.
81
82 The path expression language
83 path A relative path from one node to one of its descendants is
84 denoted by a sequence of slash separated labels. The label of a
85 child element is the element name. The label of an attribute
86 node is the attribute name prefixed by the "@" sign. The label
87 of a text content node is the string "#text". The path from one
88 node to itself is an empty path. Examples: book/title,
89 recipe/ingredient/@calories, book/author/#text.
90
91 path pattern
92 A sequence of selection steps selector!condition!selector!condi‐
93 tion.... Each step is a pair of contiguous "!" delimited fields
94 of the expression.
95
96 selector
97 Regular expression that will be matched against relative paths
98 between nodes.
99
100 condition
101 Like selectors, and may also have a trailing "/?" prefixed value
102 pattern, also given as a regular expression.
103
104 selection step
105 A selection step selects descendant-or-self nodes whose relative
106 path matches the selector, and in turn have some descendant-or-
107 self node whose relative path and text content match the condi‐
108 tion.
109
110 Examples:
111
112 book! --> selects all books.
113 book!author --> selects all books that have an author.
114 book!author/?Kipling --> selects all books written by Kipling.
115 book!@onloan --> selects all books that are loaned.
116 book!@onloan!title! --> selects the titles of all books that are
117 loaned.
118
120 The xmltree library includes both the xmlbase and the xmlwrite
121 libraries. Their functionality is implicitly available.
122
124 Currently only one XML input document is supported. And the stored node
125 tree should not be modified.
126
127 The selection facility can only be used for descendants of a root node.
128 Selectors for ascendant or sibling nodes are not supported.
129
131 XML Processing With gawk, xmlbase(3am), xmlcopy(3am), xmlsimple(3am),
132 xmlwrite(3am).
133
135 Manuel Collado, m-collado@users.sourceforge.net.
136
138 Copyright (C) 2017, Free Software Foundation, Inc.
139
140 Permission is granted to make and distribute verbatim copies of this
141 manual page provided the copyright notice and this permission notice
142 are preserved on all copies.
143
144 Permission is granted to copy and distribute modified versions of this
145 manual page under the conditions for verbatim copying, provided that
146 the entire resulting derived work is distributed under the terms of a
147 permission notice identical to this one.
148
149 Permission is granted to copy and distribute translations of this man‐
150 ual page into another language, under the above conditions for modified
151 versions, except that this permission notice may be stated in a trans‐
152 lation approved by the Foundation.
153
154
155
156GAWK Extension Library (gawkextlibJ)anuary 2017 xmltree(3am)