Skip to content

Commit 2ea26f6

Browse files
author
Erik Olofsen
committed
add cdata
1 parent 6e035b5 commit 2ea26f6

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/LightXML.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module LightXML
1313
child_nodes, has_children, attributes, has_attributes, attributes_dict,
1414
child_elements, find_element, get_elements_by_tagname,
1515

16-
new_element, add_child, new_child, new_textnode, add_text,
16+
new_element, add_child, new_child, new_textnode, add_text, add_cdata,
1717
set_attribute, set_attributes,
1818

1919
# document
@@ -27,4 +27,5 @@ module LightXML
2727
include("utils.jl")
2828
include("nodes.jl")
2929
include("document.jl")
30+
include("cdata.jl")
3031
end

src/cdata.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function new_cdatanode(xdoc::XMLDocument, txt::ASCIIString)
2+
p = ccall(xmlNewCDataBlock, Xptr, (Xptr, Xstr, Cint), xdoc.ptr, txt, length(txt)+1)
3+
XMLNode(p)
4+
end
5+
6+
add_cdata(xdoc::XMLDocument, x::XMLElement, txt::ASCIIString) = add_child(x, new_cdatanode(xdoc,txt))

src/clib.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ _xcopystr(p::Xstr) = (r = bytestring(p); _xmlfree(p); r)
4949
@lx2func xmlNewNode
5050
@lx2func xmlAddChild
5151
@lx2func xmlNewText
52+
@lx2func xmlNewCDataBlock
5253
@lx2func xmlSetProp
5354

5455
# functions for documents

test/cdata.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using LightXML
2+
3+
xdoc = XMLDocument()
4+
5+
xroot = create_root(xdoc, "States")
6+
7+
xs1 = new_child(xroot, "State")
8+
add_cdata(xdoc, xs1, "Massachussetts")
9+
10+
rtxt = """
11+
<?xml version="1.0" encoding="utf-8"?>
12+
<States>
13+
<State><![CDATA[Massachussetts]]></State>
14+
</States>
15+
"""
16+
17+
@assert strip(string(xdoc)) == strip(rtxt)
18+
19+
free(xdoc)

0 commit comments

Comments
 (0)