简体   繁体   English

在使用C解析大型XML页面时如何解决'返回null'

[英]How to solve 'returned null' when parsing a huge XML page with C

I'm trying to parse a huge XML clob data from oracle DB in Redhat linux 5.5, 64bit, using libxml2-2.7.6 我正在尝试使用libxml2-2.7.6从Redhat linux 5.5,64bit中的oracle DB解析一个巨大的XML clob数据

But when I tried to parse the XML more than 400KB(409600 bytes), the xml parser function, 'xmlParseMemory' returned null pointer. 但是当我尝试解析超过400KB(409600字节)的XML时,xml解析器函数'xmlParseMemory'返回空指针。

(Succeeded to load from XML clob data to string in C, checked the string 'sData' is filled with the data correctly.) (成功从XML clob数据加载到C中的字符串,检查字符串'sData'是否正确填充数据。)

xmlDocPtr xDoc;
...
xDoc = xmlParseMemory(sData, strlen(sData));
if(xDoc == NULL)    return -1;
...

Parser does work when the size of XML is less than 400KB. 当XML的大小小于400KB时,Parser会工作。 But only when more then 400KB, paser returns null pointer despite correct string data, 'sData'. 但只有当超过400KB时,paser才会返回空指针,尽管字符串数据正确,'sData'。

And I've already tried xmlReadDoc, xmlReadMemory with using xmlMemSetup before xmlInitParser. 我已经在xmlInitParser之前使用xmlMemSetup尝试了xmlReadDoc,xmlReadMemory。

How can I solve this situation with using xml parser functions? 如何使用xml解析器函数解决这种情况?

If everything works for XML with less than 400KB, I believe the problem is because of your sData buffer. 如果一切适用于少于400KB的XML,我相信问题是因为你的sData缓冲区。 You should check if the buffer has enough space for large file (more than 400kb): 您应该检查缓冲区是否有足够的空间容纳大文件(超过400kb):

  • How much memory you allocated for sData ? 你为sData分配了多少内存?
  • Does the strlen(sData) valid? strlen(sData)是否有效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM