Skip to content

Commit c03a93f

Browse files
committed
Add unlink, mention free and unlink in readme
1 parent aa303e8 commit c03a93f

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ add_text(xs3, "California")
162162
set_attributes(xs3; tag="CA", cap="Sacramento")
163163
```
164164

165-
**Note:** When you create XML documents and elements directly you need to take care not to leak memory; memory management in the underlying libxml2 library is complex and LightXML currently does not integrate well with Julia's garbage collection system. You can call ``free`` on an XMLDocument but if you are directly creating XMLElement's there is not yet a corresponding ``free`` function to call.
165+
**Note:** When you create XML documents and elements directly you need to take care not to leak memory; memory management in the underlying libxml2 library is complex and LightXML currently does not integrate well with Julia's garbage collection system. You can call ``free`` on an XMLDocument, XMLNode or XMLElement but you must take care not to reference any child elements after they have been manually freed.
166166

167167
#### Export an XML file
168168

@@ -242,6 +242,11 @@ get_elements_by_tagname(e, name) # a list of all child elements of e with
242242

243243
string(e) # format an XML element into a string
244244
show(io, e) # output formatted XML element
245+
246+
unlink(x) # remove a node or element from its current context
247+
# (unlink does not free the memory for the node/element)
248+
free(xdoc) # release memory for a document and all its children
249+
free(x) # release memory for a node/element and all its children
245250
```
246251

247252
##### Functions to create an XML document

src/LightXML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module LightXML
1414
child_elements, find_element, get_elements_by_tagname,
1515

1616
new_element, add_child, new_child, new_textnode, add_text, add_cdata,
17-
set_attribute, set_attributes,
17+
set_attribute, set_attributes, unlink,
1818

1919
# document
2020
XMLDocument, version, encoding, compression, standalone, root,

src/clib.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ _xcopystr(p::Xstr) = (r = bytestring(p); _xmlfree(p); r)
5353
@lx2func xmlNewCDataBlock
5454
@lx2func xmlSetProp
5555
@lx2func xmlFreeNode
56+
@lx2func xmlUnlinkNode
5657

5758
# functions for documents
5859

src/nodes.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ has_children(nd::XMLNode) = (nd._struct.children != nullptr)
146146
is_blanknode(nd::XMLNode) = bool(ccall(xmlIsBlankNode, Cint, (Xptr,), nd.ptr))
147147

148148
function free(nd::XMLNode)
149-
ccall(xmlFreeNode, Void, (Ptr{Void},), nd.ptr)
149+
ccall(xmlFreeNode, Void, (Xptr,), nd.ptr)
150150
nd.ptr = nullptr
151151
end
152152

153+
function unlink(nd::XMLNode)
154+
ccall(xmlUnlinkNode, Void, (Xptr,), nd.ptr)
155+
end
156+
153157
# iteration over children
154158

155159
immutable XMLNodeIter
@@ -212,6 +216,7 @@ Base.string(x::XMLElement) = string(x.node)
212216
Base.show(io::IO, x::XMLElement) = show(io, x.node)
213217

214218
free(x::XMLElement) = free(x.node)
219+
unlink(x::XMLElement) = unlink(x.node)
215220

216221
# attribute access
217222

0 commit comments

Comments
 (0)