创建可修改的 SqlPathExpression 对象,此对象表示路径参数所指定的路径。可修改意味着,当浏览时如果路径元素尚未存在,则将创建它们。此函数将指针返回到 PathExpression 对象,从而用作浏览路径的函数(即 cniSqlNavigatePath 系列)的输入。创建此表达式时会产生开销,因此如果您要对每个消息是使用同一路径表达式,则应调用一次此函数,并且应在调用 cniSqlNavigate 时对每个消息使用返回的 CciSqlPathExpression*。您可以在不同于创建 CciSqlPathExpression 的线程上使用此对象。
CciSqlPathExpression* cniSqlCreateModifiablePathExpression( int* returnCode, CciNode* nodeObject, CciChar* dataSourceName, CciChar* path );
如果成功,则会返回 SQLPathExpression 对象的地址。如果发生错误,则会返回 CCI_NULL_ADDR,并且此返回码参数会表明发生错 误的原因。一旦不再需要 SQLPathExpression(通常在删除节点时),应通过调用 cniSqlDeletePathExpression 来删除它。
将以下代码添加到 Transform 节点样本后,只需进行一次函数调用就能很容易地创建元素以及所有必需的祖代。
我们将在 _Transform_createNodeContext 函数中创建 CciSQLPathExpression:
{ CciChar ucsPathExpressionString[32]; char* mbPathExpressionString = "OutputRoot.XML.Request.A.B.C.D.E"; /* convert our path string to unicode*/ cciMbsToUcs(NULL, mbPathExpressionString, ucsPathExpressionString, 32, BIP_DEF_COMP_CCSID); p->pathExpression = cniSqlCreateModifiablePathExpression( NULL, nodeObject, NULL,/*we do not reference Database*/ ucsPathExpressionString); }
稍后,我们则可以在 _Transform_evaluate 函数中使用 CciSqlPathExpression
{ CciElement* newElement = cniSqlNavigatePath( NULL, ((NODE_CONTEXT_ST *)context)->pathExpression, message, destinationList, exceptionList, outMsg, NULL,/*we do not reference OutputLocalEnvironment*/ NULL/*we do not reference OutputLExceptionList*/); }
因此在输入消息 PluginSample.change.xml 中传递:
<Request type="change"> <CustomerAccount>01234567</CustomerAccount> <CustomerPhone>555-0000</CustomerPhone> </Request>
我们将看到以下输出消息。
<Request type="modify"> <CustomerAccount>01234567</CustomerAccount> <CustomerPhone>555-0000</CustomerPhone> <A> <B> <C> <D/> </C> </B> </A> </Request>