簡體   English   中英

如何使用libxml2錯誤消息

[英]how to get off with the libxml2 error messages

我想使用libxml2 lib來解析我的xml文件。 現在,當我有一些糟糕的xml文件時,lib本身正在打印大錯誤消息。

下面是一些示例代碼

reader = xmlReaderForFile(filename, NULL, 0);
if (reader != NULL) {
   ret = xmlTextReaderRead(reader);
   while (ret == 1) {
       printf("_________________________________\n");
       processNode(reader);
       ret = xmlTextReaderRead(reader);
       printf("_________________________________\n");
   }
   xmlFreeTextReader(reader);
   if (ret != 0) {
       fprintf(stderr, "%s : failed to parse\n", filename);
   }
}

在上面的例子中,如果我有錯誤的xml文件,我會得到這樣的錯誤

my.xml:4: parser error : attributes construct error
 include type="text"this is text. this might be excluded in the next occurrence 

my.xml:4: parser error : Couldn't find end of Start Tag include
 include type="text"this is text. this might be excluded in the next occurrence 

my.xml : failed to parse

相反,我只是想回復一些錯誤。 和這個丑陋的lib消息一起下車。

我該怎么辦 ?

xmlReaderForFile(filename, NULL, 0);的最后一個參數xmlReaderForFile(filename, NULL, 0); 是一組選項標志。 閱讀這些標志的文檔 ,我看到有兩個選項可能需要設置: XML_PARSE_NOERRORXML_PARSE_NOWARNING 請注意,我還沒有嘗試過任何這個,我只是用Google搜索libxml2和xmlReaderForFile。

你需要或像這樣的標志:

reader = xmlReaderForFile(filename, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM