JuliaIO / LibExpat.jl

Julia interface to the Expat XML parser library
Other
9 stars 32 forks source link

Example of streaming #91

Open johannspies opened 6 years ago

johannspies commented 6 years ago

Can you please add an example on how to use LibExpat.jl when streaming a large file to the documentation or the Jupyter notebook? For my lack of experience the template in the README is not enough to help me.

MKoesters commented 6 years ago

Hi, I would also be happy to have a more comprehensive documentation for the streaming API.

I managed to get the following running, but what I really want to do is to iterate the XML file and get back the return value of the callback to interrogate with this.

using LibExpat
using Compat

type Container
    name::String
    id::Int64
end

tag_name = "test"
L = []
cb = XPCallbacks()
cb.start_element = function (h, name, attrs)
    if name == tag_name
        id = parse(Int64, split(attrs["id"], "=")[2])
        c = Container(name, id)
        push!(L, c)
        return c
    end
end

parsefile(filename, cb)

Before I try implement an iterator myself, is there any way to do this using your package? Sry for hijacking your issue Johann, but I thought my progress so far might help you a little :) If not, just tell me and I'll move it to another Issue

Manuel