已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
B. 示例文档 John Fleck June 2, 2002 example keyword This is the headline This is the body text. C. Keyword例程代码 #include #include #include #include #include void parseStory (xmlDocPtr doc, xmlNodePtr cur) xmlChar *key; cur = cur-xmlChildrenNode; while (cur != NULL) if (!xmlStrcmp(cur-name, (const xmlChar *)keyword) key = xmlNodeListGetString(doc, cur-xmlChildrenNode, 1); printf(keyword: %sn, key); xmlFree(key); cur = cur-next; return; static void parseDoc(char *docname) xmlDocPtr doc; xmlNodePtr cur; doc = xmlParseFile(docname); if (doc = NULL ) fprintf(stderr,Document not parsed successfully. n); return; cur = xmlDocGetRootElement(doc); if (cur = NULL) fprintf(stderr,empty documentn); xmlFreeDoc(doc); return; if (xmlStrcmp(cur-name, (const xmlChar *) story) fprintf(stderr,document of the wrong type, root node != story); xmlFreeDoc(doc); return; cur = cur-xmlChildrenNode; while (cur != NULL) if (!xmlStrcmp(cur-name, (const xmlChar *)storyinfo) parseStory (doc, cur); cur = cur-next; xmlFreeDoc(doc); return; int main(int argc, char *argv) char *docname; if (argc = 1) printf(Usage: %s docnamen, argv0); return(0); docname = argv1; parseDoc (docname); return (1); libxml(三) D. XPath例程代码 #include #include #include xmlDocPtr getdoc (char *docname) xmlDocPtr doc; doc = xmlParseFile(docname); if (doc = NULL ) fprintf(stderr,Document not parsed successfully. n); return NULL; return doc; xmlXPathObjectPtr getnodeset (xmlDocPtr doc, xmlChar *xpath) xmlXPathContextPtr context; xmlXPathObjectPtr result; context = xmlXPathNewContext(doc); result = xmlXPathEvalExpression(xpath, context); if(xmlXPathNodeSetIsEmpty(result-nodesetval) printf(No resultn); return NULL; xmlXPathFreeContext(context); return result; int main(int argc, char *argv) char *docname; xmlDocPtr doc; xmlChar *xpath = (xmlChar*)/keyword; xmlNodeSetPtr nodeset; xmlXPathObjectPtr result; int i; xmlChar *keyword; if (argc nodesetval; for (i=0; i nodeNr; i+) /keyword=(xmlChar*)0; keyword = xmlNodeListGetString(doc, nodeset-nodeTabi-xmlChildrenNode, printf(keyword: %sn, keyword); xmlFree(keyword); xmlXPathFreeObject (result); xmlFreeDoc(doc); xmlCleanupParser(); return (1); E. 添加keyword例程代码 #include #include #include #include #include void parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) xmlNewTextChild (cur, NULL, keyword, keyword); return; xmlDocPtr parseDoc(char *docname, char *keyword) xmlDocPtr doc; xmlNodePtr cur; doc = xmlParseFile(docname); if (doc = NULL ) fprintf(stderr,Document not parsed successfully. n); return (NULL); cur = xmlDocGetRootElement(doc); if (cur = NULL) fprintf(stderr,empty documentn); xmlFreeDoc(doc); return (NULL); if (xmlStrcmp(cur-name, (const xmlChar *) story) fprintf(stderr,document of the wrong type, root node != story); xmlFreeDoc(doc); return (NULL); cur = cur-xmlChildrenNode; while (cur != NULL) if (!xmlStrcmp(cur-name, (const xmlChar *)storyinfo) parseStory (doc, cur, keyword); cur = cur-next; return(doc); int main(int argc, char *argv) char *docname; char *keyword; xmlDocPtr doc; if (argc = 2) printf(Usage: %s docname, keywordn, argv0); return(0); docname = argv1; keyword = argv2; doc = parseDoc (docname, keyword); if (doc != NULL) xmlSaveFormatFile (docname, doc, 0); xmlFreeDoc(doc); return (1); F. 添加属性例程代码 #include #include #include #include #include xmlDocPtr parseDoc(char *docname, char *uri) xmlDocPtr doc; xmlNodePtr cur; xmlNodePtr newnode; xmlAttrPtr newattr; doc = xmlParseFile(docname); if (doc = NULL ) fprintf(stderr,Document not parsed successfully. n); return (NULL); cur = xmlDocGetRootElement(doc); if (cur = NULL) fprintf(stderr,empty documentn); xmlFreeDoc(doc); return (NULL); if (xmlStrcmp(cur-name, (const xmlChar *) story) fprintf(stderr,document of the wrong type, root node != story); xmlFreeDoc(doc); return (NULL); newnode = xmlNewTextChild (cur, NULL, reference, NULL); newattr = xmlNewProp (newnode, uri, uri); return(doc); int main(int argc, char *argv) char *docname; char *uri; xmlDocPtr doc; if (argc = 2) printf(Usage: %s docname, urin, argv0); return(0); docname = argv1; uri = argv2; doc = parseDoc (docname, uri); if (doc != NULL) xmlSaveFormatFile (docname, doc, 1); xmlFreeDoc(doc); return (1); G. 取得属性值例程代码 #include #include #include #include #include void getReference (xmlDocPtr doc, xmlNodePtr cur) xmlChar *uri; cur = cur-xmlChildrenNode; while (cur != NULL) if (!xmlStrcmp(cur-name, (const xmlChar *)storyinfo) uri = xmlGetProp(cur, uri); printf(uri: %sn, uri); xmlFree(uri); cur = cur-next; return; void parseDoc(char *docname) xmlDocPtr doc; xmlNodePtr cur; doc = xmlParseFile(docname); if (doc = NULL ) fprintf(stderr,Document not parsed successfully. n); return; cur = xmlDocGetRootElement(doc); if (cur = NULL) fprintf(stderr,empty documentn); xmlFreeDoc(doc); return; if (xmlStrcmp(cur-name, (const xmlChar *) story) fprintf(stderr,document of the wrong type, root node != story); xmlFreeDoc(doc); return; getReference (doc, cur); xmlFreeDoc(doc); return; int main(int argc, char *argv) char *docname; if (argc = 1) printf(Usage: %s docnamen, argv0); return(0); docname = argv1; parseDoc (docname); return (1); H. 编码转换例程代码 #include #include unsigned char* convert (unsigned char *in, char *encoding) unsigned char *out; int ret,size,out_size,temp; xmlCharEncodingHandlerPtr handler; size = (int)strlen(in)+1; out_size = size*2-1; out = malloc(size_t)out_size); if (out) handler = xmlFindCharEncodingHandler(encoding); if (!handler) free(out); out = NULL; if (out) temp=size-1; ret = handler-input(out, &out_size, in, &temp); if (ret | temp-size+1) if (ret) printf(conversion wasnt successful.n); else printf(conversion wasnt successful. converted: free(out); out = NULL; else out = realloc(out,out_size+1); outout_size=0; /*null terminating out*/ else printf(no memn); return (out); int main(int argc, char *argv) unsigned char *content, *out; xmlDocPtr doc; xmlNodePtr rootnode; char *encoding = ISO-8859-1; if (argc = 1) printf(U
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2020-2025年一级建造师之一建建设工程经济模拟题库及答案下载
- 胆囊粘液囊肿的护理
- 雨课堂学堂在线学堂云《财务管理(重庆邮电大学 )》单元测试考核答案
- 房地产 -建设工程在竣工验收之前发包人擅自投入使用发包人能否以使用部分工程质量不符合合同约定为由向承包人主张权利
- 七上语文名著《西游记》中考真题及答案
- 小说《西游记》阅读练习题(附答案)
- 2026年陕西省选调生招录(面向西安电子科技大学)备考公基题库带答案解析
- 2026年劳务员之劳务员基础知识考试题库200道及一套参考答案
- 2026年劳务员之劳务员基础知识考试题库200道带答案(模拟题)
- 2025福州工业园区开发集团有限公司勘察设计分公司招聘2人备考题库带答案解析
- 业主委员会成员推荐表
- 期货基础知识(期货入门)
- 房产公司施工图设计标准
- YY/T 1603-2018医用内窥镜内窥镜功能供给装置摄像系统
- GB/T 615-2006化学试剂沸程测定通用方法
- 新闻学概论复习-
- 土的孔隙率试验检测报告
- 气相色谱仪火焰光度检测器(FPD)使用手册
- 全科病例汇报 重度低钠血症
- 飞利浦DFM100除颤仪
- 钢板桩引孔施工方法
评论
0/150
提交评论