有人能给我任何暗示怎么做? 使用下面的代码我可以读取数据,但我不知道我是否破坏了节点。
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.
更多推荐
发布评论