Problem iterating relations

Jan 22, 2013 at 4:01 PM
Edited Jan 22, 2013 at 4:04 PM

HI every one.

I am making a reader and render for docx files and using libopc to read it.

Well, I have a problem to get the images "id", then I decided get the image "Id" by the same way that opcContainerDump method is printing this information. For beginning I tried to print every relationship by using the code that I see in libopc documentation but the code is crashing...

opcContainer *c = opcContainerOpen(_X(filePath.c_str()),  OPC_OPEN_READ_ONLY,  NULL,  NULL);
if (c)
{
		
    for(opcPart part=opcPartGetFirst(c);OPC_PART_INVALID!=part;part=opcPartGetNext(c, part)) {
	   for(opcRelation rel=opcRelationFirst(c, part); OPC_PART_INVALID!=rel; rel=opcRelationNext(c, part, rel)) {
		   opcPart internal_target=opcRelationGetInternalTarget(c, part, rel);
		   const xmlChar *external_target=opcRelationGetExternalTarget(c, part, rel);
		   const xmlChar *target=(NULL!=internal_target?internal_target:external_target);
		   const xmlChar *prefix=NULL;
		   opc_uint32_t counter=-1;
		   const xmlChar *type=NULL;
		   opcRelationGetInformation(c, part, rel, &prefix, &counter, &type);        
		   if (-1==counter) { /* no counter after prefix */
			  printf("%s;%s;%s;%s\n", part, prefix, target, type);
		   } else {
			  printf("%s;%s%i;%s;%s\n", part, prefix, counter, target, type);
		   }
	   }
}
...
....

 

 

Any suggestion?

Many thanks and great library!

Jan 22, 2013 at 4:32 PM
Edited Jan 22, 2013 at 4:35 PM

Well, I have just fixed my problem but I think the solution is not "elegant".

I could see when a part has no relations opcRelationFirst return UINT_MAX as relation. Then:

 

 for(opcPart part=opcPartGetFirst(c);OPC_PART_INVALID!=part;part=opcPartGetNext(c, part)) {
		 //printf("%s;%s \n", part, opcPartGetType(c, part));
	   for(opcRelation rel=opcRelationFirst(c, part);
		 OPC_PART_INVALID!=rel; rel=opcRelationNext(c, part, rel)) 
      {
		   if (rel == UINT_MAX) break;
			...
			...
       }
}

As I said, I dont like the solution, Could somebody get de images "id" by other way or with a more elegant code?
Many Thanks!

Jan 22, 2013 at 4:51 PM
Edited Jan 22, 2013 at 4:53 PM

Well, sorry for the question, the real problem was at example code!!!!!!!!!!!!

In the second loop, "rel" must be compared with OPC_RELATION_INVALID instead of OPC_PART_INVALID.

 

Regards!