XML 解析(和验证)C 程序的分析
感谢 Stack Overflow 上的 jmbr,我终于找到了一种通过 C 程序针对 RELAX NG 验证 xml 的方法。该程序如下...
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/relaxng.h>
int main(int argc, char *argv[])
{
int status;
xmlDoc *doc;
xmlRelaxNGPtr schema;
xmlRelaxNGValidCtxtPtr validctxt;
xmlRelaxNGParserCtxtPtr rngparser;
doc = xmlParseFile(argv[1]);
rngparser = xmlRelaxNGNewParserCtxt(argv[2]);
schema = xmlRelaxNGParse(rngparser);
validctxt = xmlRelaxNGNewValidCtxt(schema);
status = xmlRelaxNGValidateDoc(validctxt, doc);
printf("status == %d\n", status);
xmlRelaxNGFree(schema);
xmlRelaxNGFreeValidCtxt(validctxt);
xmlRelaxNGFreeParserCtxt(rngparser);
xmlFreeDoc(doc);
exit(EXIT_SUCCESS);
}
从那时起,我对程序进行了重大调整,以便找出解析和验证 xml 文件的“处理时间”。有什么方法可以找出该程序的最佳情况和最坏情况。最坏的情况是,对于任何作为输入的 xml 文件,所花费的时间始终是最高的。最好的情况是,所花费的时间总是最短的。我真的很困惑。如果你们中有人能帮助我,我将非常感激。
Thanks to jmbr at Stack Overflow, I finally found a way to validate xml against RELAX NG via a C program. The program is as follows...
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/relaxng.h>
int main(int argc, char *argv[])
{
int status;
xmlDoc *doc;
xmlRelaxNGPtr schema;
xmlRelaxNGValidCtxtPtr validctxt;
xmlRelaxNGParserCtxtPtr rngparser;
doc = xmlParseFile(argv[1]);
rngparser = xmlRelaxNGNewParserCtxt(argv[2]);
schema = xmlRelaxNGParse(rngparser);
validctxt = xmlRelaxNGNewValidCtxt(schema);
status = xmlRelaxNGValidateDoc(validctxt, doc);
printf("status == %d\n", status);
xmlRelaxNGFree(schema);
xmlRelaxNGFreeValidCtxt(validctxt);
xmlRelaxNGFreeParserCtxt(rngparser);
xmlFreeDoc(doc);
exit(EXIT_SUCCESS);
}
I have, since then, significantly tweaked the program so as to find out the "processing time" for parsing and validating an xml file. Is there any way to find out the best case and worst case for this program. Worst case being, the time taken is always highest for any xml file as input. And best case being, the time taken is always lowest. I am really stuck at this. Would really appreciate it, if any of you guys could help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要测试您的代码,您应该制定不同的测试计划和测试计划。测试用例..
在这种情况下尝试不同的不同的 xml 输入文件...
1 个文件,其嵌套多次
任何丢失的标签 xml 文件(无效的 xml 文件)
没有 doctype 或标签的 xml 文件采用不同的编码
&用于计算处理时间使用 time.h
To test your code you should make different test plan & test case..
in that case Try different different xml input file ...
1 file who whose nesting so many times
any missed tag xml file (not valid xml file)
xml file who has no doctype or tags are in differently coded
& for processing time calculation use time.h