@@ -5,7 +5,7 @@ immutable _XMLDocStruct # use the same layout as C
5
5
# common part
6
6
_private:: Ptr{Void}
7
7
nodetype:: Cint
8
- name:: Ptr{Cchar}
8
+ name:: Xstr
9
9
children:: Xptr
10
10
last:: Xptr
11
11
parent:: Xptr
@@ -48,7 +48,7 @@ type XMLDocument
48
48
49
49
function XMLDocument ()
50
50
# create an empty document
51
- ptr = ccall (xmlNewDoc, Xptr, (Ptr{Cchar} ,), " 1.0" )
51
+ ptr = ccall (( : xmlNewDoc ,libxml2), Xptr, (Cstring ,), " 1.0" )
52
52
XMLDocument (ptr)
53
53
end
54
54
end
@@ -59,59 +59,59 @@ compression(xdoc::XMLDocument) = @compat Int(xdoc._struct.compression)
59
59
standalone (xdoc:: XMLDocument ) = @compat Int (xdoc. _struct. standalone)
60
60
61
61
function root (xdoc:: XMLDocument )
62
- pr = ccall (xmlDocGetRootElement, Ptr{Void} , (Ptr{Void} ,), xdoc. ptr)
63
- pr != nullptr || throw (XMLNoRootError ())
62
+ pr = ccall (( : xmlDocGetRootElement ,libxml2), Xptr , (Xptr ,), xdoc. ptr)
63
+ pr != C_NULL || throw (XMLNoRootError ())
64
64
XMLElement (pr)
65
65
end
66
66
67
67
68
68
# ### construction & free
69
69
70
70
function free (xdoc:: XMLDocument )
71
- ccall (xmlFreeDoc, Void, (Ptr{Void} ,), xdoc. ptr)
72
- xdoc. ptr = nullptr
71
+ ccall (( : xmlFreeDoc ,libxml2), Void, (Xptr ,), xdoc. ptr)
72
+ xdoc. ptr = C_NULL
73
73
end
74
74
75
75
function set_root (xdoc:: XMLDocument , xroot:: XMLElement )
76
- ccall (xmlDocSetRootElement, Xptr, (Xptr, Xptr), xdoc. ptr, xroot. node. ptr)
76
+ ccall (( : xmlDocSetRootElement,libxml2) , Xptr, (Xptr, Xptr), xdoc. ptr, xroot. node. ptr)
77
77
end
78
78
79
- function create_root (xdoc:: XMLDocument , name:: String )
79
+ function create_root (xdoc:: XMLDocument , name:: AbstractString )
80
80
xroot = new_element (name)
81
81
set_root (xdoc, xroot)
82
82
return xroot
83
83
end
84
84
85
85
# ### parse and free
86
86
87
- function parse_file (filename:: String )
88
- p = ccall (xmlParseFile, Xptr, (Ptr{Cchar} ,), filename)
89
- p != nullptr || throw (XMLParseError (" Failure in parsing an XML file." ))
87
+ function parse_file (filename:: AbstractString )
88
+ p = ccall (( : xmlParseFile ,libxml2), Xptr, (Cstring ,), filename)
89
+ p != C_NULL || throw (XMLParseError (" Failure in parsing an XML file." ))
90
90
XMLDocument (p)
91
91
end
92
92
93
- function parse_string (s:: String )
94
- p = ccall (xmlParseMemory, Xptr, (Ptr{Cchar} , Cint), s, sizeof (s) + 1 )
95
- p != nullptr || throw (XMLParseError (" Failure in parsing an XML string." ))
93
+ function parse_string (s:: AbstractString )
94
+ p = ccall (( : xmlParseMemory ,libxml2), Xptr, (Xstr , Cint), s, sizeof (s) + 1 )
95
+ p != C_NULL || throw (XMLParseError (" Failure in parsing an XML string." ))
96
96
XMLDocument (p)
97
97
end
98
98
99
99
100
100
# ### output
101
101
102
- function save_file (xdoc:: XMLDocument , filename:: String ; encoding:: String = " utf-8" )
103
- ret = ccall (xmlSaveFormatFileEnc, Cint, (Ptr{Cchar} , Xptr, Ptr{Cchar} , Cint),
102
+ function save_file (xdoc:: XMLDocument , filename:: AbstractString ; encoding:: AbstractString = " utf-8" )
103
+ ret = ccall (( : xmlSaveFormatFileEnc ,libxml2), Cint, (Cstring , Xptr, Cstring , Cint),
104
104
filename, xdoc. ptr, encoding, 1 )
105
105
if ret < 0
106
106
throw (XMLWriteError (" Failed to save XML to file $filename " ))
107
107
end
108
108
return @compat Int (ret) # number of bytes written
109
109
end
110
110
111
- function Base. string (xdoc:: XMLDocument ; encoding:: String = " utf-8" )
111
+ function Base. string (xdoc:: XMLDocument ; encoding:: AbstractString = " utf-8" )
112
112
buf_out = Array (Xstr, 1 )
113
113
len_out = Array (Cint, 1 )
114
- ccall (xmlDocDumpFormatMemoryEnc, Void, (Xptr, Ptr{Xstr}, Ptr{Cint}, Ptr{Cchar} , Cint),
114
+ ccall (( : xmlDocDumpFormatMemoryEnc ,libxml2), Void, (Xptr, Ptr{Xstr}, Ptr{Cint}, Cstring , Cint),
115
115
xdoc. ptr, buf_out, len_out, encoding, 1 )
116
116
_xcopystr (buf_out[1 ])
117
117
end
0 commit comments