Deprecated. XML Maps are deprecated as of the WebLogic Platform 8.1 release. For new code, use XQuery maps. For more information, see Introduction to XQuery Maps.

How Do I: Use ECMAScript (JavaScript) to Process XML Messages?

Sometimes the transformations needed to process incoming or outgoing XML messages are more complex than you can accomplish with static XML maps. In these cases, you can use WebLogic Workshop's extended version of ECMAScript to perform XML mappings. To do so, you must first create a script file (with a JSX extension) in your project to hold the script.

To Create a Script File

  1. From the File menu, choose New-->Other File Types. The New File dialog appears.
  2. In the left-hand window, select the Web Services folder.
  3. In the right-hand window, select XScript.
  4. In the File name field, type a name for the new script file.
  5. Click OK.

The newly created JSX file contains two functions named myScriptFromXML and myScriptToXML. These are used to map from XML to Java types and to XML from Java types. The newly created JSX file also contains some rudimentary instructions about how to use the script from a map.

From within a map, script may be called by using the following syntax:

{ScriptFileName.myScript(parameters)}

Notice that the function name in the call does not include ToXML or FromXML. The appropriate method in the JavaScript file is determined automatically based on the direction of the mapping being performed.

The value of parameters depends on whether you are mapping the parameters or the return value of your Java declaration. If you are placing the call to script in a parameter-xml map, parameters should be the arguments of the method or callback that you would like this script method to populate. If you are placing the call to script in a return-xml map, you should simply enter type return, where type is the method or callback's declared return type.

Related Topics

Handling XML with ECMAScript Extensions

Handling and Shaping XML Messages with XML Maps