C++使用libxml解析XML文件(二)

2014-02-08 13:36:28 · 作者: · 浏览: 183

 

  attrPtr = attrPtr->next;

  }

  // Label

  xmlNodePtr childNodePtr = itemNodePtr->xmlChildrenNode;

  while (childNodePtr != NULL){

  int l=0,t=0,r=0,b=0;

  attrPtr = childNodePtr->properties;

  while(attrPtr != NULL){

  if (!xmlStrcmp(attrPtr->name, BAD_CAST "l")){

  xmlChar* szAttr = xmlGetProp(childNodePtr,BAD_CAST "l");

  l=atoi((char*)szAttr);

  xmlFree(szAttr);

  }

  if (!xmlStrcmp(attrPtr->name, BAD_CAST "t")){

  xmlChar* szAttr = xmlGetProp(childNodePtr,BAD_CAST "t");

  t=atoi((char*)szAttr);

  xmlFree(szAttr);

  }

  if (!xmlStrcmp(attrPtr->name, BAD_CAST "r")){

  xmlChar* szAttr = xmlGetProp(childNodePtr,BAD_CAST "r");

  r=atoi((char*)szAttr);

  xmlFree(szAttr);

  }

  if (!xmlStrcmp(attrPtr->name, BAD_CAST "b")){

  xmlChar* szAttr = xmlGetProp(childNodePtr,BAD_CAST "b");

  b=atoi((char*)szAttr);

  xmlFree(szAttr);

  }

  if (!xmlStrcmp(attrPtr->name, BAD_CAST "id")){

  xmlChar* szAttr = xmlGetProp(childNodePtr,BAD_CAST "id");

  peopleID=atoi((char*)szAttr);

  xmlFree(szAttr);

  }

  attrPtr = attrPtr->next;

  }

  if(!(l==0&&t==0&&b==0&&r==0)){

  rect.x=l;rect.y=t;rect.width=r-l;rect.height=b-t;

  labels[pair<int,int>(frameNum,peopleID)] = rect;

  //cout《"get label: "《l《" "《t《" "《r《" "《b《" "《" "《peopleID《endl;

  }

  childNodePtr = childNodePtr->next;

  }

  itemNodePtr = itemNodePtr->next;

  }

  xmlFreeDoc(doc);

  return filename;

  }

  用map的iterator输出:

  for(map<pair<int,int>,Rect >::iterator it=labels.begin();

  it!=labels.end();it++){

  cout《(*it)。first.first《" "《(*it)。first.second《" "

  《(*it)。second.x《" "《(*it)。second.y《" "

  《(*it)。second.width《" "《(*it)。second.height《endl;

  }