Skip to content

Commit

Permalink
Merge pull request #22 from yeesian/master
Browse files Browse the repository at this point in the history
use iobuffer instead of string for streaming files
  • Loading branch information
amitmurthy committed Jan 3, 2015
2 parents b569941 + 2e9ea87 commit e03f03c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/streaming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ function parsefile(filename::String,callbacks::XPCallbacks; bufferlines=1024, da
# TODO: Support suspending for files too
suspended = false
file = open(filename, "r")

try
io = IOBuffer()
while !eof(file)
i::Int = 0
txt::String = ""
truncate(io, 0)
while i < bufferlines && !eof(file)
txt *= readline(file)
write(io, readline(file))
i += 1
end
txt = bytestring(io)
rc = XML_Parse(h.parser, txt, length(txt.data), 0)
if (rc != XML_STATUS_OK) && (XML_GetErrorCode(h.parser) != XML_ERROR_ABORTED)
# Do not fail if the user aborted the parsing
Expand Down
7 changes: 4 additions & 3 deletions src/xpath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
# XPath Spec: http://www.w3.org/TR/xpath/

import Base.typeseq
import Compat

const xpath_axes = Dict{String, Symbol}(
const xpath_axes = Compat.@Dict(
"ancestor" => :ancestor,
"ancestor-or-self" => :ancestor_or_self,
"attribute" => :attribute,
Expand All @@ -25,13 +26,13 @@ const xpath_axes = Dict{String, Symbol}(
"preceding-sibling" => :preceding_sibling,
"self" => :self)

const xpath_types = Dict{String, (Symbol,DataType)}(
const xpath_types = Compat.@Dict(
"comment" => (:comment,String),
"text" => (:text,String),
# "processing-instruction" => (:processing_instruction, ??),
"node" => (:node,Any))

const xpath_functions = Dict{String, (Symbol,Int,Int,DataType)}( # (name, min args, max args)
const xpath_functions = Compat.@Dict( # (name, min args, max args)
#node-set
"last" => (:last,0,0,Int),
"position" => (:position,0,0,Int),
Expand Down

0 comments on commit e03f03c

Please sign in to comment.