logo
WXT, a Web and Xml Tool
from Ostfold College
: Introduction > Documentation > The PIs >TextImport

PI: import-text

The purpose is to import text that is not necessarily wellformed XML. The imported text may be modified in several ways and is

  • inserrted as a textnode
  • inserted as an XML-fragment
  • saved to file for possible HTTP Request
<?_wxt import-text uri="" leftpar="" rightpar="" select= "" parse="" type="" request_file="" request_function="" expanded=""?>

The parameters are:

uri (optional in templates) The URI of the file we want to import from. In templates the uri parameter is usually skipped. In this case all content files listed in the script are searched for appropriate content.
leftpar (optional) Any string in the text that may serve as a left bracket for a selection.
rightpar (optional) Any string in the text that may serve as a right bracket for a selection.
select (optional)
Has only meaning when leftpar and rightpar is set. Select describes which of possibly many text fragments that should be included. Possible values are:
  • all
  • random
  • n:m
all is default. random picks one fragment at random fromr the available textfragments.
n and m are integers describing low and hi index of the fragments we want to use. Indexing starts at 1. select="1" use the first fragment. Negative numbers start counting in the right end, select="-1" selects the last fragment. select="1:3" select the three first fragments.
replace (optional) Will do a simple replace in the collected string, before possible codeformatting or parsing. Format is replace="old|new". Will replace "old" with "new". The divider, |, may be changed by option: replace_divider in script. | is default. You may have many replaces: replace, replace1,replace2 etc. Not suitable for large replace operations, just for simple masking of addresses, passwords etc.
parse (optional) Possible values are "yes" or "no" with "no" as default. Set this parameter to "yes" if you want WXT to attempt to parse the selected text as an XML-fragment.
type (optional)
Reckognized values are: javacode, javascriptcode, cppcode, ccode, csharpcode, xsltcode, aspxcode, pythoncode, mlcode.
If either of these is found WXT attempts to produce programcode with hilited keywords, stringliterals and comments. To get the full effect from this you must supply a stylesheet with the following styles: .nncode, .nnword, .nnliteral and .nncomment, where nn is ml, java, javascript, c, cpp, csharp, xslt, aspx or python. See Styling
Note that this is not a fullblown language parser, it simply attempts to identify and hilite elements in a codefragment. If the parser fails, it will simply wrap the supposed code in a pre-tag: <pre class="code">..</pre>. You should therefore also prepare the .code - style to meet this possibility.
request_file (optional) A simple filename. The file will be produced in the catalog of the owning page and an expansion-button will be placed in the page. Relies on a Javascript for a HTTPRequest, see AJAX. The CSS class "onoff" should be set to taylor the look of this expansion-button.
request_function (optional) A name of the Javascript function that will be involved when we try to expand the fragment. Default value is "expand", see AJAX.
expanded (optional) Values are yes | no. no is default. Has only meaning when request-file is set. If yes: The fragment is showed initially, with unexpand-functionality.

If either or both of leftpar and rightpar is not set, the whole file is imported. If parse is set and fails, nothing is imported. If type is set, parse is ignored.

If request_file is set, only a simple button-like reference is set in the page.

A few examples:

<?_wxt import-text uri="../p/main.c"
          leftpar="//inlude"
          rightpar="//end-include"?>
<?_wxt import-text
         leftpar="<!-- begin -->"
         rightpar="<!-- end -->"
         parse="yes"?>
<?_wxt import-text uri="../code/test.java"
         leftpar="/*START_PART*/"
         rightpar="/*END_PART*/"
         replace="hemmelig|mypassword"
         type="javacode"?>
<?_wxt import-text uri="../code/test.java"
         type="javacode"?
         request_file="test_java.txt">
<?_wxt import-text uri="../code/test.java"
         type="javacode"?
         request_file="test_java.txt"
         expanded="yes">

WXT, a Web and Xml Tool from Ostfold College: http://www.ia.hiof.no/~borres/wxtdoc/


Bygget med WXT : 11.jan.2009