You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+48-48Lines changed: 48 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## LightXML.jl
2
2
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:
4
4
5
5
* Parse a XML file or string into a tree
6
6
* Access XML tree structure
@@ -54,7 +54,7 @@ using LightXML
54
54
xdoc =parse_file("ex1.xml")
55
55
56
56
# get the root element
57
-
xroot =root(xdoc) # an instance of XMLElement
57
+
xroot =root(xdoc) # an instance of XMLElement
58
58
# print its name
59
59
println(name(xroot)) # this should print: bookstore
One can also traverse all attributes of an element ``e`` as
99
+
One can also traverse all attributes of an element (``e1``) as
100
100
101
101
```julia
102
-
for a inattributes(e) # a is an instance of XMLAttr
102
+
for a inattributes(e1) # a is an instance of XMLAttr
103
103
n =name(a)
104
104
v =value(a)
105
105
println("$n = $v")
@@ -110,7 +110,7 @@ Another way to access attributes is to turn them into a dictionary using ``attri
110
110
111
111
```julia
112
112
ad =attributes_dict(e1)
113
-
v = ad["lang"] # v <-- "en"
113
+
v = ad["category"] # v <-- "COOKING"
114
114
```
115
115
116
116
**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
187
187
*``XMLNode``: represent a generic XML node (``child_nodes`` give you this)
188
188
*``XMLAttr``: represent an XML attribute
189
189
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)``.
191
191
192
192
193
193
### API Functions
@@ -200,27 +200,27 @@ A list of API functions:
200
200
```julia
201
201
# Let xdoc be a document, x be a node/element, e be an element
202
202
203
-
root(xdoc) # get the root element of a document
203
+
root(xdoc) # get the root element of a document
204
204
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
209
209
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
214
214
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
217
217
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
221
221
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
224
224
225
225
has_attribute(e, name) # whether a named attribute exists for e
226
226
@@ -236,43 +236,43 @@ find_element(e, name) # the first element of specified name under e
236
236
get_elements_by_tagname(e, name) # a list of all child elements of e with
237
237
# the specified name
238
238
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
241
241
```
242
242
243
243
##### Functions to create an XML document
244
244
245
245
```julia
246
-
xdoc =XMLDocument() # create an empty XML document
246
+
xdoc =XMLDocument() # create an empty XML document
247
247
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
250
250
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
253
253
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
256
256
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
259
259
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
262
262
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
265
265
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
268
268
269
269
set_attribute(e, name, value) # set an attribute of an element
270
270
# this returns the added attribute
271
271
# as an instance of XMLAttr
272
272
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)
276
276
277
277
# one can also use keyword arguments to set attributes to an element
0 commit comments