cpiCreateAndInitializeElement
This function creates a syntax element, owned by the specified parser, that is not attached to a syntax tree. The element is partially initialized with the values of the type, name, firstChildComplete, and lastChildComplete parameters.
Syntax
CciElement* cpiCreateAndInitializeElement(
int* returnCode,
CciParser* parser,
CciElementType type,
const CciChar* name,
CciBool firstChildComplete,
CciBool lastChildComplete);
Parameters
- returnCode
- Receives the return code from the function (output). Possible return codes are:
- CCI_SUCCESS
- CCI_EXCEPTION
- CCI_FAILURE
- CCI_INV_PARSER_OBJECT
- parser
- Specifies the address of the parser object (input). This address is passed to the parser as a parameter of the cpiCreateContext implementation function.
- type
- Specifies the type of the element being created (input).
- name
- Specifies a descriptive name for the element (input).
- firstChildComplete
- Specifies a value for the firstChildComplete flag of the syntax element (input).
- lastChildComplete
- Specifies a value for the lastChildComplete flag of the syntax element (input).
Return values
If successful, the address of the new element object is returned. Otherwise, a value of zero (CCI_NULL_ADDR) is returned, and returnCode indicates the reason for the error.
Sample
/* Advance to the end of the value */
while (pc->iCurrentCharacter != quoteChar) {
advance( (PARSER_CONTEXT_ST *)context, parser );
}
/* Get a pointer to the end of the tag */
endMarker = (char*)pc->iBuffer+(int)pc->iIndex;
/* Compute the size of the tag */
markedSize = (size_t)endMarker-(int)startMarker;
/* Convert the attribute value into integration node form */
data = CciNString((char *)startMarker, markedSize, pc->iCcsid);
/* Create a new name-value element for the attribute */
newElement = cpiCreateAndInitializeElement(&rc, parser, type, name);
cpiSetElementType(&rc, newElement, CCI_ELEMENT_TYPE_NAME_VALUE);
cpiSetElementName(&rc, newElement, data);
if (pc->trace) {
const char * mbData = mbString(data, pc->iCcsid);
fprintf(pc->tracefile, "PLUGIN: Created new NAMEVALUE element;
object=0x%x type=0x%x name=",
newElement, CCI_ELEMENT_TYPE_NAME_VALUE);
fprintf(pc->tracefile, "%s\n", mbData);
fflush(pc->tracefile);
free((void *)mbData);
}
/* Free the memory created in CciNString() */
free((void *)data);