2
在libxml中,我嘗試選擇第一個元素來使用xpath驗證條件。如果我理解正確,「xpath [包含(@ id,'art')] [1]」只會給出一個元素,儘管我得到的不止一個元素。我在libxml教程中使用函數getnodeset(請參閱here)。下面是代碼:在libxml中選擇使用xPath驗證一個convolution的第一個元素
xmlXPathObjectPtr result=getnodeset(def,(xmlChar*) "//div[contains(@id,'art')][1]"); // where def is a htmlDocPtr
xmlNodeSetPtr nodeset;
if(result)
{
nodeset=result->nodesetval;
if(nodeset->nodeNr>1)
fprintf(stderr,"%i first div with id attribute *art* : %s\n",nodeset->nodeNr,nomDef);
}