Editing EDML files

 < Day Day Up > 

You must maintain Dreamweaver coding conventions when you edit a file. Pay attention to the dependency of one element upon another. For example, if you update the tags that are being inserted, you might also need to update the search patterns.

NOTE

EDML files were new in Dreamweaver MX. If you are working with legacy server behaviors, see the earlier versions of the Extending Dreamweaver manuals.


Regular expressions

You must understand regular expressions as they are implemented in JavaScript 1.5. You must also know when it is appropriate to use them in the server behavior EDML files. For example, regular expressions cannot be used in quickSearch values, but they are used in the content of the searchPattern tag to find and extract data.

Regular expressions describe text strings by using characters that are assigned with special meanings (metacharacters) to represent the text, break it up, and process it according to predefined rules. Regular expressions are powerful parsing and processing tools because they provide a generalized way to represent a pattern.

Good reference books on JavaScript 1.5 have a regular expression section or chapter. This section examines how Dreamweaver server behavior EDML files use regular expressions in order to find parameters in your runtime code and extract their values. Each time a user edits a server behavior, prior parameter values need to be extracted from the instances of the runtime code. You use regular expressions for the extraction process.

You should understand a few metacharacters and metasequences (special character groupings) that are useful in server behavior EDML files, as described in the following table:

Regular Expression

Description

\

Escapes special characters. For example: \. reverts the metacharacter back to a literal period; \/ reverts the forward slash to its literal meaning; and, \) reverts the parens to its literal meaning.

/ ... /i

Ignore case when searching for the metasequence

( ...)

Creates a parenthetical subexpression within the metasequence

\s*

Searches for white spaces


The EDML tag <searchPatterns whereToSearch="directive"> declares that runtime code needs to be searched. Each <searchPattern>...</searchPattern> subtag defines one pattern in the runtime code that must be identified. For the Redirect If Empty example, there are two patterns.

In the following example, to extract parameter values from <% if (@@rs@@.EOF) Response.Redirect("@@new__url@@"); %>,write a regular expression that identifies any string rs and new__url:

 <searchPattern paramNames="rs,new__url">   /if d ((\w+)\.EOF\) Response\.Redirect\("([^\r\n]*)"\)/i </searchPattern> 

This process searches the user's document, and if there is a match, extracts the parameter values. The first parenthetical subexpression (\w+) exTRacts the value for rs. The second subexpression ([^\r\n]*) exTRacts the value for new_url.

NOTE

The character sequence "[^\r\n]*" matches any character that is not a linefeed, for the Macintosh and Windows.


Notes about EDML structure

You should use a unique filename to identify your server behavior group. If only one group file uses an associated participant file, match the participant filename with the group name. Using this convention, the server behavior group file updateRecord.edml works with the participant file updateRecord_init.edml. When participant files might be shared among server behavior groups, assign unique descriptive names.

NOTE

The EDML name space is shared, regardless of folder structure, make sure you use unique filenames. Filenames should not exceed 31 characters (including the .edml extension), due to Macintosh limitations.


The runtime code for your server behavior resides inside the EDML files. The EDML parser should not confuse any of your runtime code with EDML markup, so the CDATA tag must wrap around your runtime code. The CDATA tag represents character data and is any text that is not EDML markup. When you use the CDATA tag, the EDML parser won't try to interpret it as markup, but instead, considers it as a block of plain text. The CDATA-marked blocks begin with <![CDATA[ and end with ]]>.

If you insert the text Hello, World, it is simple to specify your EDML, as shown in the following example:

 <insertText>Hello, World</insertText> 

However, if you insert content that has tags in it, such as <img sr1c='foo.gif'>, it can confuse the EDML parser. In that case, embed it in the CDATA construct, as shown in the following example:

 <insertText><![CDATA[<img s1rc='foo.gif'>]]></insertText> 

The ASP runtime code is wrapped within the CDATA tag, as shown in the following example:

 <![CDATA[   <% if (@@rs@@.EOF) Response.Redirect("@@new__url@@"); %> ]] 

Because of the CDATA tag, the ASP tags <%= %>, along with the other content within the tag, aren't processed. Instead, the Extension Data Manager (EDM) receives the uninterpreted text, as shown in the following example:

 <% if (Recordset1.EOF) Response.Redirect("http://www.macromedia.com"); %> 

In the following EDML definitions, the locations where the CDATA tag is recommended are indicated in the examples.

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net