开发者

how to use libxml2 to parse data from GInputStream (GLibGIO/GVFS)?

In a GTK application, I'm using xmlParseFile() from libxml2. However, that function can only read local files. How can I instead make it use the GIO framework, so that it can read remote files as well?

The simplest way is probably to use something like g_file_load_contents() to read the entire file into memory, then call xmlParseMemory() to parse that. However, I'm looking for a "nicer" solution which ideally streams the data (to avoid keeping the entire data in memory); possibly by connecting a GInputStream to libxml2?

Code examples wel开发者_如何学JAVAcome. I would guess this is a common use case, so collecting an exhaustive list of good implementations here might be useful.


There are instructions (with code examples) on the libxml2 website about how to parse XML data chunk by chunk from a file: http://xmlsoft.org/library.html#Invoking1

If you wanted to use GInputStream then you could use g_input_stream_read() to feed chunks to xmlParseChunk() in the same manner as the example program in the libxml2 documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜