Skip to content

Commit 1c8cd4d

Browse files
committed
Fix doc typos, code examples
1 parent 5f8c189 commit 1c8cd4d

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

README.md

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## LightXML.jl
22

3-
This package is a light-weight Julia wrapper of [Libxml2](http://www.xmlsoft.org), which provides a minimal interface that covers functionalities that are commonly needed:
3+
This package is a light-weight Julia wrapper of [libxml2](http://www.xmlsoft.org), which provides a minimal interface that covers functionalities that are commonly needed:
44

55
* Parse a XML file or string into a tree
66
* Access XML tree structure
@@ -54,7 +54,7 @@ using LightXML
5454
xdoc = parse_file("ex1.xml")
5555

5656
# get the root element
57-
xroot = root(xdoc) # an instance of XMLElement
57+
xroot = root(xdoc) # an instance of XMLElement
5858
# print its name
5959
println(name(xroot)) # this should print: bookstore
6060

@@ -90,16 +90,16 @@ println(attribute(e1, "category"))
9090
t = find_element(e1, "title")
9191

9292
# retrieve the value of lang attribute of t
93-
a = attribute(t, "lang") # a <- "en"
93+
a = attribute(t, "lang") # a <- "en"
9494

9595
# retrieve the text content of t
9696
r = content(t) # r <- "Everyday Italian"
9797
```
9898

99-
One can also traverse all attributes of an element ``e`` as
99+
One can also traverse all attributes of an element (``e1``) as
100100

101101
```julia
102-
for a in attributes(e) # a is an instance of XMLAttr
102+
for a in attributes(e1) # a is an instance of XMLAttr
103103
n = name(a)
104104
v = value(a)
105105
println("$n = $v")
@@ -110,7 +110,7 @@ Another way to access attributes is to turn them into a dictionary using ``attri
110110

111111
```julia
112112
ad = attributes_dict(e1)
113-
v = ad["lang"] # v <-- "en"
113+
v = ad["category"] # v <-- "COOKING"
114114
```
115115

116116
**Note:** The functions ``child_nodes``, ``child_elements``, and ``attributes`` return light weight iterators -- so that one can use them with for-loop. To get an array of all items, one may use the ``collect`` function provided by Julia.
@@ -187,7 +187,7 @@ Main types of this package
187187
* ``XMLNode``: represent a generic XML node (``child_nodes`` give you this)
188188
* ``XMLAttr``: represent an XML attribute
189189

190-
Note that one if an ``XMLNode`` instance ``x`` is actually an element node, one may construct an ``XMLElement`` instance by ``XMLElement(x)``.
190+
**Note:** If an ``XMLNode`` instance ``x`` is actually an element node, one may construct an ``XMLElement`` instance by ``XMLElement(x)``.
191191

192192

193193
### API Functions
@@ -200,27 +200,27 @@ A list of API functions:
200200
```julia
201201
# Let xdoc be a document, x be a node/element, e be an element
202202

203-
root(xdoc) # get the root element of a document
203+
root(xdoc) # get the root element of a document
204204

205-
nodetype(x) # get an integer indicating the node type
206-
name(x) # get the name of a node/element
207-
content(x) # get text content of a node/element
208-
# if x is an element, this returns all text (concatenated) within x
205+
nodetype(x) # get an integer indicating the node type
206+
name(x) # get the name of a node/element
207+
content(x) # get text content of a node/element
208+
# if x is an element, this returns all text (concatenated) within x
209209

210-
is_elementnode(x) # whether x is an element node
211-
is_textnode(x) # whether x is a text node
212-
is_cdatanode(x) # whether x is a CDATA node
213-
is_commentnode(x) # whether x is a comment node
210+
is_elementnode(x) # whether x is an element node
211+
is_textnode(x) # whether x is a text node
212+
is_cdatanode(x) # whether x is a CDATA node
213+
is_commentnode(x) # whether x is a comment node
214214

215-
has_children(e) # whether e has child nodes
216-
has_attributes(e) # whether e has attributes
215+
has_children(e) # whether e has child nodes
216+
has_attributes(e) # whether e has attributes
217217

218-
child_nodes(x) # iterator of all child nodes of a node/element x
219-
child_elements(e) # iterator of all child elements of e
220-
attributes(e) # iterator of all attributes of e
218+
child_nodes(x) # iterator of all child nodes of a node/element x
219+
child_elements(e) # iterator of all child elements of e
220+
attributes(e) # iterator of all attributes of e
221221

222-
attributes_dict(e) # a dictionary of all attributes of e,
223-
# which maps names to corresponding values
222+
attributes_dict(e) # a dictionary of all attributes of e,
223+
# which maps names to corresponding values
224224

225225
has_attribute(e, name) # whether a named attribute exists for e
226226

@@ -236,43 +236,43 @@ find_element(e, name) # the first element of specified name under e
236236
get_elements_by_tagname(e, name) # a list of all child elements of e with
237237
# the specified name
238238

239-
string(e) # Format an XML element into a string
240-
show(io, e) # output formatted XML element
239+
string(e) # format an XML element into a string
240+
show(io, e) # output formatted XML element
241241
```
242242

243243
##### Functions to create an XML document
244244

245245
```julia
246-
xdoc = XMLDocument() # create an empty XML document
246+
xdoc = XMLDocument() # create an empty XML document
247247

248-
e = new_element(name) # create a new XML element
249-
# this does not attach e to a tree
248+
e = new_element(name) # create a new XML element
249+
# this does not attach e to a tree
250250

251-
t = new_textnode(content) # create a new text node
252-
# this does not attach t to a tree
251+
t = new_textnode(content) # create a new text node
252+
# this does not attach t to a tree
253253

254-
set_root(xdoc, e) # set element e as the root of xdoc
255-
add_child(parent, x) # add x as a child of a parent element
254+
set_root(xdoc, e) # set element e as the root of xdoc
255+
add_child(parent, x) # add x as a child of a parent element
256256

257-
e = create_root(xdoc, name) # create a root element and set it as root
258-
# equiv. to new_element + set_root
257+
e = create_root(xdoc, name) # create a root element and set it as root
258+
# equiv. to new_element + set_root
259259

260-
e = new_child(parent, name) # create a new element and add it as a child
261-
# equiv. to new_element + add_child
260+
e = new_child(parent, name) # create a new element and add it as a child
261+
# equiv. to new_element + add_child
262262

263-
add_text(e, text) # add text content to an element
264-
# equiv. to new_textnode + add_child
263+
add_text(e, text) # add text content to an element
264+
# equiv. to new_textnode + add_child
265265

266-
add_cdata(xdoc, e, text) # add cdata content to an element
267-
# equiv. to new_cdatanode + add_child
266+
add_cdata(xdoc, e, text) # add cdata content to an element
267+
# equiv. to new_cdatanode + add_child
268268

269269
set_attribute(e, name, value) # set an attribute of an element
270270
# this returns the added attribute
271271
# as an instance of XMLAttr
272272

273-
set_attributes(e, attrs) # set multiple attributes in one call
274-
# attrs can be a dictionary or
275-
# a list of pairs as (name, value)
273+
set_attributes(e, attrs) # set multiple attributes in one call
274+
# attrs can be a dictionary or
275+
# a list of pairs as (name, value)
276276

277277
# one can also use keyword arguments to set attributes to an element
278278
set_attributes(e, key1="val1", key2="val2", ...)
@@ -281,10 +281,10 @@ set_attributes(e, key1="val1", key2="val2", ...)
281281
##### Functions to work with a document
282282

283283
```julia
284-
xdoc = parse_file(filename) # parse an XML file
285-
xdoc = parse_string(str) # parse an XML doc from a string
286-
save_file(xdoc, filename) # save xdoc to an XML file
284+
xdoc = parse_file(filename) # parse an XML file
285+
xdoc = parse_string(str) # parse an XML doc from a string
286+
save_file(xdoc, filename) # save xdoc to an XML file
287287

288-
string(xdoc) # Formatted XML doc to a string
289-
show(io, xdoc) # output formatted XML document
288+
string(xdoc) # formatted XML doc to a string
289+
show(io, xdoc) # output formatted XML document
290290
```

0 commit comments

Comments
 (0)