锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品一区二,蜜桃久久久久,亚洲精品视频在线观看网站http://www.aygfsteel.com/pdw2009/category/46023.html鏈珯涓嶅啀鏇存柊錛屾榪庡厜涓? <a >java寮鍙戞妧鏈綉</a>zh-cnThu, 16 Sep 2010 13:05:22 GMTThu, 16 Sep 2010 13:05:22 GMT60libxml涓嬌鐢▁path瑙f瀽xml鏂囦歡http://www.aygfsteel.com/pdw2009/archive/2010/08/23/329638.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Mon, 23 Aug 2010 04:06:00 GMThttp://www.aygfsteel.com/pdw2009/archive/2010/08/23/329638.htmlhttp://www.aygfsteel.com/pdw2009/comments/329638.htmlhttp://www.aygfsteel.com/pdw2009/archive/2010/08/23/329638.html#Feedback0http://www.aygfsteel.com/pdw2009/comments/commentRss/329638.htmlhttp://www.aygfsteel.com/pdw2009/services/trackbacks/329638.html #include <libxml/xpath.h>                                                            
#include <stdio.h>                                                                   
                                                                                     
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);                                                 
 if (context == NULL) {                                                             
  printf("Error in xmlXPathNewContext\n");                                         
  return NULL;                                                                     
 }                                                                                  
 result = xmlXPathEvalExpression(xpath, context);                                   
 xmlXPathFreeContext(context);                                                      
 if (result == NULL) {                                                              
  printf("Error in xmlXPathEvalExpression\n");                                     
  return NULL;                                                                     
 }                                                                                  
 if(xmlXPathNodeSetIsEmpty(result->nodesetval)){                                    
  xmlXPathFreeObject(result);                                                      
    printf("No result\n");                                                           
  return NULL;                                                                     
 }                                                                                  
 return result;                                                                     
}                                                                                    
                                                                                     
                                                                                     
                                                                                     
                                                                                     
                                                                                     
int main(int argc, char **argv) {                                                    
                                                                                     
 char *docname;                                                                     
 xmlDocPtr doc;                                                                     
 xmlChar *xpath = (xmlChar*) "http://keyword";                                           
 xmlNodeSetPtr nodeset;                                                             
 xmlXPathObjectPtr result;                                                          
 int i;                                                                             
 xmlChar *keyword;                                                                  
                                                                                   
 if (argc <= 1) {                                                                   
  printf("Usage: %s docname\n", argv[0]);                                          
  return(0);                                                                       
 }                                                                                  
                                                                                     
 docname = argv[1];                                                                 
 doc = getdoc(docname);                                                             
 result = getnodeset (doc, xpath);                                                  
 if (result) {                                                                      
  nodeset = result->nodesetval;                                                    
  for (i=0; i < nodeset->nodeNr; i++) {                                            
   keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);  
    printf("keyword: %s\n", keyword);                                              
    xmlFree(keyword);                                                              
  }                                                                                
  xmlXPathFreeObject (result);                                                     
 }                                                                                  
 xmlFreeDoc(doc);                                                                   
 xmlCleanupParser();                                                                
 return (1);                                                                        
}                                                                                

demo.xml

 <?xml version="1.0" encoding="UTF-8"?>                 
<story>                                                
  <storyinfo>                                          
    <author>John Fleck</author>                        
    <datewritten>June 2, 2002</datewritten>            
    <keyword>example keyword瑁?lt;/keyword>                
  </storyinfo>                                         
  <body>                                               
    <headline>This is the headline</headline>          
    <para>This is the body text.</para>                
  </body>                                              
</story>                                                
    
                                                                                     

鎭寵甯崟鍑諱竴涓嬪箍鍛?


]]>
主站蜘蛛池模板: 五家渠市| 化隆| 湟源县| 泸溪县| 垦利县| 中江县| 河津市| 额济纳旗| 新和县| 遂昌县| 阿拉尔市| 简阳市| 策勒县| 榆树市| 博罗县| 邻水| 邢台市| 栖霞市| 大方县| 玉田县| 翼城县| 苍南县| 崇阳县| 马关县| 廉江市| 涟源市| 枞阳县| 鄢陵县| 阳江市| 登封市| 甘南县| 玉屏| 贡觉县| 玉山县| 江都市| 芦山县| 杭锦后旗| 日土县| 锦州市| 凤凰县| 扶余县|