Using Batch Modify with WebPublisher PRO


Copyright © 2006 Inmagic, Inc. All rights reserved.

Batch Modify is used to make the same change to multiple records at once. Records can have entries added to beginning or end of a field, before or after a matching entry, or the records can have entries deleted, either matching entries or all entries. Records can also have specific words or letters replaced within a field or specific entry. To do this, you will construct a similar function as outlined in the other operations, but with additional attributes and associated values.
 

Batch Modify uses an AC value of BATCH_MODIFY:
 
function batchModify(){

strXmlInput = '<?xml version="1.0" ?>\n' +
'<Query xmlns="http://www.inmagic.com/webpublisher/query">\n' +
'<AC>BATCH_MODIFY</AC>\n' +
'<TN>Cars</TN>\n' +
 

The first attribute to be specified in the AC tag is the batchModAction attribute. This tells WebPublisher PRO what type of modification to perform. It has valid values of insertEntry, appendEntry, substEntry, deleteEntry, and substText. The batchModAction attribute has a default value of substEntry, which will overwrite a specified entry with the new entry. To insert an entry, for example:
 
'<AC batchModAction="insertEntry">BATCH_MODIFY</AC>' +
 

If the AC tag is left as is, the new entry will be inserted before the first entry in the field. This is because there is no batchModEntry attribute specified for the AC and batchModEntry attribute has a default value of first. To tell WebPublisher to insert an entry before a matching entry, set the batchModEntry value to matching:
 

'<AC batchModAction="insertEntry" batchModEntry="matching">BATCH_MODIFY</AC>' +
 
When you specify batchModEntry="matching", you must also specify the value of entry to be matched. Do this with the OE element (Old Entry). For example, to insert the new entry before the entry Silver, specify:
 
'<AC batchModAction ="insertEntry" batchModEntry="matching" >BATCH_MODIFY</AC>' +
'<OE>Silver</OE>' +
 
When used with batchModAction="substText", two additional attributes can be specified. To specify that a match should be case-sensitive, use matchCase="Y". To specify that the match must be satisified by whole words only, use matchWholeWord="Y". The default is N if either of these attributes is omitted. For example:
 
'<AC batchModAction="insertEntry" batchModEntry="matching" matchCase="N" matchWholeWord="Y">BATCH_MODIFY</AC>'+
 

There are two more elements in a batch modify request:

  • <FN> specifies the field that will be modified.
  • <EN> specifies the new information to be inserted or substituted in the field.

This example will insert new entry Orange before existing entry Silver:
 

'<FN>Colors</FN>' +
'<EN>Orange</EN>' +
 

The last required element specifies the set of records to be amended. Use the >QY element to enter a command query that will retrieve the set of records to be modified. (To learn more about structuring queries, you can use the command query window in DB/TextWorks or CS/TextWorks.) This element replaces the <Recordset> and <Record> elements discussed in the previous topics. For example, to insert Orange before Silver in all records that contain the latter term but not the former, use the following:
 

'<QY>Find Colors = Silver NOT Colors = Orange</QY>'+
 

Lastly, as in all the other examples, you have to close the Query tag and return the XML to the calling page or function:
 

'</Query>';
return strXmlInput;
}

Special characters in Batch Modify

WebPublisher PRO has some unique values that can be used in the OE and EN attributes that are not available in other edit-over-the-Web functionality. Specifically, the ability to enter in new lines, multiple new entries in one pass, and the ability to add beginning and ending text to an existing entry. This functionality is accomplished by using {LF} where you want to specify a line feed, {SF} where you want to specify a new entry marker, and {*} where you want to insert beginning and ending text. {*} is only available with substitute entry and will take the existing field value and wrap the entries with whatever text comes before and after the {*}. For example, to insert "My favorite color is" before all of the entries in the Colors field in the Cars textbase, you would specify the AC tag attributes of batchModAction="substEntry", a batchModEntry="all", and set the EN value to My Favorite Color is {*}:
 
'<AC batchModAction="substEntry" batchModEntry="all">BATCH_MODIFY</AC>' +
'<EN>My favorite color is {*}</EN>' +
 
To add multiple entries in one pass, for instance to add the colors Orange and Tan to the beginning of the Colors field:
 
'<AC batchModAction="insertEntry" batchModEntry="first" >BATCH_MODIFY</AC>' +
'<EN>Orange{SF}Tan</EN>' +
 
To change the line breaks in a field to entry delimiters, perhaps because line breaks are indistinguishable from other whitespace in XML:
 
<AC batchModAction="substText" batchModEntry="all" >BATCH_MODIFY</AC>'+<
'<EN>{SF}</EN>'+
'<OE>{LF}</OE>+

There is an example of this function (buildWpQueryForBatchModify() ) in XmlToWpp.ASP.

See it in action