doTranslateFromNative Function Translator XPath Functions

6-52 Oracle Fusion Middleware Users Guide for Technology Adapters Example 6–1 Configuring the XPath Function When the Input Data Is of String Type and Must Be Converted to an XML DOM variables variable… variable name=csv_data type=xsd:string variables assign name=assignCSVData copy from expression=this, is, csv, data… to variable=csv_data copy assign assign name=doTranslateFromNativeCall copy from expression=ora: doTranslateFromNative bpws:getVariableDatacsv_ data,xsdaddress-csv.xsd,Root-Element,DOM to variable=returnVariable query=ns1:Root-Element copy assign In this example: ■ csv_data is a BPEL variable containing CSV data to be translated into XML. ■ xsdaddress-csv.xsd is relative path to the NXSD schema in the project. ■ Root-Element is a root element in the NXSD schema This is optional. ■ returnVariable is the returned XML data as DOM. Example 6–2 When the Input data is an Attachment, Which Must Be Translated to a DOM 1. Define attachmentElement in the schema of the BPEL process, as follows: schema targerNamespace=… element name=attachmentElement complexType attribute name=href type=string complexType element schema 2. Create a variable of type attachment element in the schema of the BPEL process, as follows: variables variable… variable name=attachmentVariable type=client:attachmentElement variables 3. Assign the source file path that you must translate, as follows: assign name=AssignAttachmentReference copy from expression=tmpxpathinaddress.csv to variable=attachmentVariable attachmentElement This parameter is optional. This is the attachment for the returned XML file. Parameter Description Native Format Builder Wizard 6-53 query=client:attachmentElementhref copy assign 4. Call the XPath function, as follows: assign name=xlateFromNative copy from expression=ora:doTranslateFromNativebpws:getVariableDataattachmentVariable ,xsdaddress-csv.xsd, Root-Element, DOM to variable=returnVariable query=ns1:Root-Element copy assign In this example: ■ attachmentVariable is an attachment variable in BPEL referring to the source file path. ■ xsdaddress-csv.xsd is the relative path to the NXSD schema in the project. ■ Root-Element is a root element in the NXSD schema. ■ returnVariable is the XML data returned as DOM. Example 6–3 Configuring XPath Function When the Input Data Is Base64-encoded and Must Be Translated to DOM 1. Define the base64-encoded element in the schema of the BPEL process, as follows: schema targerNamespace=… element name=mtomElement type=base64Binary schema 2. Create a variable of type mtom element in the schema of the BPEL process, as follows: variables variable… variable name=encodedData type=client:mtomElement variables 3. Assign the source file path that you need to translate, as follows assign name=assignBase64EncodedData copy from expression=b3JhY2xl to variable=encodedData query=client:mtomElement copy assign assign name=doTranslateFromNativeCall copy from expression=ora: doTranslateFromNative bpws:getVariableDataencodedData,xsdaddress-csv.xsd,Root-Element,DOM to variable=returnVariable query=ns1:Root-Element copy assign In this example: 6-54 Oracle Fusion Middleware Users Guide for Technology Adapters ■ mtomElement is a BPEL variable containing base64-encoded data to be translated into XML. ■ xsdaddress-csv.xsd is the relative path to the NXSD schema in the project. ■ Root-Element is a root element in the NXSD schema. ■ returnVariable is the XML data returned as DOM. Example 6–4 Configuring XPath Function When the Input Data Is of String Type, Which Must Be Translated to an Attachment Referred to by a File-Path 1. Define attachmentElement in the schema of the BPEL process, as follows: schema targerNamespace=… element name=attachmentElement complexType attribute name=href type=string complexType element schema 2. Create an input variable of type string and an output variable of type attachment in the schema of the BPEL process, as follows: variables variable… variable name=csv_data type=xsd:string variable name=returnAttachmentVariable type=client:attachmentElement variables 3. Assign the CSV data that you need to translate, as follows: assign name=assignCSVData copy from expression=this, is, csv, data… to variable=csv_data copy assign 4. Populate the attachment with the path of the file where you want the translated data to be stored, as follows: assign name=AssignAttachmentReferenceForOutput copy from expression=tmpxpathoutputaddress.xml to variable= returnAttachmentVariable query=client:attachmentElementhref copy assign 5. Call the XPath function as follows: assign name=doTranslateFromNativeCall copy from expression=ora: doTranslateFromNative bpws:getVariableDatacsv_ data,xsdaddress-csv.xsd,Root-Element,ATTACHMENT, bpws:getVariableDatareturnAttachmentVariable to variable=returnAttachmentVariable copy assign In this example: Native Format Builder Wizard 6-55 ■ csv_data is a BPEL string variable containing CSV data to be translated into XML. ■ xsdaddress-csv.xsd is the relative path to the NXSD schema in the project. ■ Root-Element is a root element in the NXSD schema. ■ returnAttachmentVariable is the returned attachment. Note: In this example, targetType is set to ATTACHMENT, and returnAttachmentVariable points to the file path where the translated XML is to be written. However, the fifth parameter bpws:getVariableDatareturnAttachmentVariable is optional. If this parameter is missing, then the XPath function creates a database-backed attachment and returns it. In such a case, the XPath function is configured, as follows: 1. Define attachmentElement in the schema of the BPEL process, as follows: schema targerNamespace=… element name=attachmentElement complexType attribute name=href type=string complexType element schema 2. Create an input variable of type string and an output variable of type attachment in the schema of the BPEL process, as follows: variables variable… variable name=csv_data type=xsd:string variable name=returnAttachmentVariable type=client:attachmentElement variables 3. Assign the CSV data that you need to translate, as follows: assign name=assignCSVData copy from expression=this, is, csv, data… to variable=csv_data copy assign assign name=doTranslateFromNativeCall copy from expression=ora: doTranslateFromNative bpws:getVariableDatacsv_ data,xsdaddress-csv.xsd,Root-Element,ATTACHMENT to variable=returnAttachmentVariable copy assign After the XPath call returns, the returnAttachmentVariable variable is populated with the href attribute pointing to the GUID representing the database-backed attachment. Note: If the data being translated is huge, then you must use either ATTACHMENT or SDOM as the targetType parameter for the XPath function. 6-56 Oracle Fusion Middleware Users Guide for Technology Adapters

6.3.2.2 doTranslateToNative Function

The doTranslateToNative XPath function translates an input DOM into string data or an attachment. Syntax: ora:dotranslateToNativeinput,nxsdTemplate,nxsdRoot,targe tType ,attachmentElement? The following table describes the parameters used in the syntax for using this function: Example 6–5 Configuring the XPath Function When the Input Data Is of XML Format and Must Be Translated Into CSV String Format variables variable… variable name=inputDOM type=ns1:Root-Element - - data that needs to be translated into native - - variable name=returned_csv_data type=xsd:string variables assign name=doTranslateToNativeCall copy from expression=ora: doTranslateToNative bpws:getVariableDatainputDOM,xsdaddress-csv.xsd,Root-Element,STRING to variable=returned_csv_data copy assign In this example: ■ inputDOM is a BPEL DOM variable containing XML data to be translated into string data representing the translated CSV. ■ xsdaddress-csv.xsd is the relative path to the NXSD schema in the project. Parameter Description input Input data for the XPath function; the data can either be DOM or SDOM data that must be translated to a native format such as CSV. nxsdTemplate NXSD schema to be used to translate the input data into XML format. nxsdRoot Name of the root element in the NXSD schema. targetType This parameter decides how the XPath function translates the XML data into native formats. Must be set to either STRING, or ATTACHMENT. If the targetType parameter is: ■ STRING, then the translated data is returned as a string. ■ ATTACHMENT, then the translated data is returned as an attachment. If the optional parameter attachmentElement is available to the XPath function, then the XPath function uses the corresponding href attribute to write the translated native data. However, if the parameter is absent, then the XPath function creates a new database-backed attachment and returns that. See Example 6–6 for more details. attachmentElement This parameter is optional. This is the attachment to which the translated data is written. Native Format Builder Wizard 6-57 ■ Root-Element is a root element in the NXSD schema. ■ return_csv_data is the string variable that contains the translated CSV data. Example 6–6 Configuring XPath Function to Translate an Incoming XML DOM into an Attachment Representing the Target File-Path for the Translated CSV 1. Define attachmentElement in the schema of the BPEL process, as follows: schema targerNamespace=… element name=attachmentElement complexType attribute name=href type=string complexType element schema 2. Create an input variable of type attachmentElement in the schema of the BPEL process, as follows: variables variable… variable name=inputDOM type=ns1:Root-Element variable name=attachmentVariable type=client:attachmentElement variables 3. Assign the target file path where you want the translated CSV to be written, as follows: assign name=AssignAttachmentReference copy from expression=tmpxpathoutaddress.csv to variable=attachmentVariable query=client:attachmentElementhref copy assign 4. Call the XPath function, as follows: assign name=xlateToNative copy from expression=ora:doTranslateToNativebpws:getVariableDatainputDOM,xsdaddre ss-csv.xsd, Root-Element, ATTACHMENT, bpws:getVariableData attachmentVariable to variable=attachmentVariable copy assign In this example: ■ inputDOM is a BPEL DOM variable containing XML data to be translated into a CSV output file represented by tmpxpathoutaddress.csv. ■ xsdaddress-csv.xsd is the relative path to the NXSD schema in the project. ■ Root-Element is a root element in the NXSD schema. ■ AttachmentElement points to the target output file path represented by tmpxpathoutaddress.csv.