ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>国产一区在线免费观看,亚洲一区二区日本,尤物精品在线http://www.aygfsteel.com/pdw2009/category/46023.html本站不再更新åQŒæ¬¢˜qŽå…‰ä¸? <a >java开发技术网</a>zh-cnThu, 16 Sep 2010 13:05:22 GMTThu, 16 Sep 2010 13:05:22 GMT60libxml中ä‹É用xpath解析xmlæ–‡äšghttp://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>                                                
    
                                                                                     

恌™¯·å¸®å•å‡ÖM¸€ä¸‹å¹¿å‘?


]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º Ë«°ØÏØ| èë´¨ÏØ| ÓÀ¼ªÏØ| ¿µÀÖÏØ| ÂÖÌ¨ÏØ| ¸£½¨Ê¡| Èý½­| ³¤´ºÊÐ| Ì«°×ÏØ| ÎäÒØÏØ| ÎåÁ«ÏØ| Ð˺£ÏØ| ÉÏÈÄÏØ| ³£ÄþÊÐ| ÇàÉñÏØ| ÄÏÑôÊÐ| ÄáÂêÏØ| ÎIJýÊÐ| Ô£ÃñÏØ| ÀëµºÇø| ¹®ÁôÏØ| ÎäѨÊÐ| ¿µ¶¨ÏØ| ÓÀ·áÏØ| Õã½­Ê¡| Î人ÊÐ| ³ÐµÂÏØ| ¶¼°²| ÃÜɽÊÐ| ÇØ°²ÏØ| ÕÑÆ½ÏØ| ¿â¶ûÀÕÊÐ| ÁÙ²×ÊÐ| º½¿Õ| Ë«ÅÆÏØ| ¶«ÎÚÖéÄÂÇ߯ì| °²Â½ÊÐ| Ëà±±| èï´¨ÏØ| »·áÏØ| ÑÓÇìÏØ|