/usr/share/doc/lua-expat-dev/us/examples.html is in lua-expat-dev 1.2.0-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>LuaExpat: XML Expat parsing for the Lua programming language</title>
<link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"><a href="http://www.keplerproject.org">
<img alt="LuaExpat logo" src="luaexpat.png"/>
</a></div>
<div id="product_name"><big><strong>LuaExpat</strong></big></div>
<div id="product_description">XML Expat parsing for the Lua programming language</div>
</div> <!-- id="product" -->
<div id="main">
<div id="navigation">
<h1>LuaExpat</h1>
<ul>
<li><a href="index.html">Home</a>
<ul>
<li><a href="index.html#overview">Overview</a></li>
<li><a href="index.html#status">Status</a></li>
<li><a href="index.html#download">Download</a></li>
<li><a href="index.html#history">History</a></li>
<li><a href="index.html#references">References</a></li>
<li><a href="index.html#credits">Credits</a></li>
<li><a href="index.html#contact">Contact</a></li>
</ul>
</li>
<li><a href="manual.html">Manual</a>
<ul>
<li><a href="manual.html#introduction">Introduction</a></li>
<li><a href="manual.html#installation">Installation</a></li>
<li><a href="manual.html#parser">Parser Objects</a></li>
</ul>
</li>
<li><strong>Examples</strong></li>
<li><a href="lom.html">Lua Object Model</a></li>
<li><a href="http://luaforge.net/projects/luaexpat/">Project</a>
<ul>
<li><a href="http://luaforge.net/tracker/?group_id=13">Bug Tracker</a></li>
<li><a href="http://luaforge.net/scm/?group_id=13">CVS</a></li>
</ul>
</li>
<li><a href="license.html">License</a></li>
</ul>
</div> <!-- id="navigation" -->
<div id="content">
<h2><a name="examples"></a>Examples</h2>
<p>The code excerpt below creates a parser with 2 callbacks and
feeds a test string to it. The parsing of the test string triggers
the callbacks, printing the results.</p>
<pre class="example">
require"lxp"
local count = 0
callbacks = {
StartElement = function (parser, name)
io.write("+ ", string.rep(" ", count), name, "\n")
count = count + 1
end,
EndElement = function (parser, name)
count = count - 1
io.write("- ", string.rep(" ", count), name, "\n")
end
}
p = lxp.new(callbacks)
for l in io.lines() do -- iterate lines
p:parse(l) -- parses the line
p:parse("\n") -- parses the end of line
end
p:parse() -- finishes the document
p:close() -- closes the parser
</pre>
<p>For a test string like</p>
<pre class="example">
<elem1>
text
<elem2/>
more text
</elem1>
</pre>
<p>The example would print</p>
<pre class="example">
+ elem1
+ elem2
- elem2
- elem1
</pre>
<p>Note that the text parts are not handled since the corresponding
callback (<em>CharacterData</em>) has not been defined. Also note
that defining this callback after the call to lxp.new would make no
difference. But had the callback table been defined as</p>
<pre class="example">
callbacks = {
StartElement = function (parser, name)
io.write("+ ", string.rep(" ", count), name, "\n")
count = count + 1
end,
EndElement = function (parser, name)
count = count - 1
io.write("- ", string.rep(" ", count), name, "\n")
end,
CharacterData = function (parser, string)
io.write("* ", string.rep(" ", count), string, "\n")
end
}
</pre>
<p>The results would have been</p>
<pre class="example">
+ elem1
* text
+ elem2
- elem2
* more text
- elem1
</pre>
<p>Another example would be the use of <em>false</em> as a
placeholder for the callback. Suppose that we would like to print
only the text associated with <em>elem2</em> elements and that the
XML sample is</p>
<pre class="example">
<elem1>
text
<elem2>
inside text
</elem2>
more text
</elem1>
</pre>
<p>We could define the new callback table as</p>
<pre class="example">
callbacks = {
StartElement = function (parser, name)
if name == "elem2" then
-- redefines CharacterData behaviour
callbacks.CharacterData = function (parser, string)
io.write(string, "\n")
end
end
end,
EndElement = function (parser, name)
if name == "elem2" then
callbacks.CharacterData = false -- restores placeholder
end
end,
CharacterData = false -- placeholder
}
</pre>
<p>The results would have been</p>
<pre class="example">
inside text
</pre>
<p>Note that this example assumes no other elements are present
inside elem2 tags.</p>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
<p><small>
$Id: examples.html,v 1.5 2006/03/23 00:19:37 carregal Exp $
</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
|