Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing XML from IOBuffer #172

Open
alhirzel opened this issue Feb 12, 2022 · 0 comments
Open

Parsing XML from IOBuffer #172

alhirzel opened this issue Feb 12, 2022 · 0 comments

Comments

@alhirzel
Copy link

Wondering if readxml(::IOBuffer) is a valid use case?

# works
xml = "<text>Hello, World</text>"
@show parsexml(xml)

# ERROR: LoadError: XMLError: Document is empty from XML parser (code: 4, line: 1)
io = IOBuffer()
write(io, xml)
@show readxml(io)

I think the current readxml function may be dependent on the layout of IOStream? Perhaps the following needs to be adapted to work for ::IO rather than just ::IOStream:

EzXML.jl/src/document.jl

Lines 147 to 160 in 8cc2855

function readxml(input::IO)
readcb = make_read_callback()
closecb = C_NULL
context = pointer_from_objref(input)
uri = C_NULL
encoding = C_NULL
options = 0
doc_ptr = @check ccall(
(:xmlReadIO, libxml2),
Ptr{_Node},
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Cstring, Cint),
readcb, closecb, context, uri, encoding, options) != C_NULL
return Document(doc_ptr)
end

I think the context argument needs to be a C FILE *? It was difficult for me to find clear documentation for libxml2. I'm happy to PR a fix+tests once I understand what to do with an IOBuffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant