读取XML流。(Reading XML stream.)

编程入门 行业动态 更新时间:2024-10-26 10:35:19
读取XML流。(Reading XML stream.)

有人能给我任何暗示怎么做? 使用下面的代码我可以读取数据,但我不知道我是否破坏了节点。

for (;;) { bytes_received = recv ( socket_handle , input_buffer , 20000, 0 ) ; if ( bytes_received == -1 ) { printf ( "An error occured during the receive procedure \n" ) ; return 0 ; } if ( bytes_received == 0 ) break ; printf ( "%s" , input_buffer ) ; }

我应该将其写为文件并使用其他语言来处理它吗? 或者我可以将其保存在RAM中并从那里处理? 用c做它是否合理?

Could someone give me any hint how to do that? With the code below I can read the data, but I have no idea if I break the node or not.

for (;;) { bytes_received = recv ( socket_handle , input_buffer , 20000, 0 ) ; if ( bytes_received == -1 ) { printf ( "An error occured during the receive procedure \n" ) ; return 0 ; } if ( bytes_received == 0 ) break ; printf ( "%s" , input_buffer ) ; }

Should I write it as file and use rather other language to process it? Or can I save it in RAM and process from there? Is it reasonable to do it with c?

最满意答案

使用C以流式方式读取XML是完全合理的。你最想要的是所谓的SAX解析器。 看看libxml的SAX接口 。

当您从例如套接字读取它们时,SAX解析器通过递增地为它们提供字节来工作。 每当他们检测到元素被启动,文本被解析等时,他们就会调用回调函数,该函数允许您以增量方式处理XML流。

It's perfectly plausible to read XML in a streaming fashion using C. What yo most likely want is a so-called SAX parser. Have a look at the SAX interface of libxml.

SAX parsers work by incrementially feeding them bytes as you read them from e.g. a socket. Every time they detect that an element is started, a text was parsed etc. they invoke a callback function which lets you process the XML stream in an incremental fashion.

更多推荐

本文发布于:2023-07-29 20:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319359.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:XML   Reading   stream

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!