Project | WXT | Basics | Download | Documentation | Samples

PI: importwiki

The purpose of an importwiki PI is to produce an XML-fragment from extracts from a wiki-page and replace the PI with this fragment.

NOTE: That the form of this PI may change. Specially the use of dpath, and the form of the dpath may be changed. It is present at an experimental stage.

<?_wxt importwiki dpath="" location=""?>

As wikipages by their nature are changing, WXT apply a strategy that backs up the latest successfull import, and use this if an import fails. The backup strategy does not consider changes in content, but if your dpath or xpath, se below, fails to identify any material at all, the backup is used. More about DPath and XPath .

This backup strategy cost processing time. You may change the strategy by parameter usecopy, see below.

The parameters are:

dpath optional The content of any header(h1, h2,.., h6) in the wikipage. Content will be extracted until we meet a heading with same or higher significance. dpath (documentpath) has the form: h1/h2/h3. For instance /Report/summary will extract content in h3:summary "under" h2:report.
Either dpath or xpath must be set. Ifdpath is set, xpath is ignored. dpath may also have a specification part.
/Report/summary[p] will collect only paragraphs in the selected part. See DPath .
xpath optional Defaults to //body.
Either dpath or xpath must be set. Ifdpath is set, xpath is ignored
location mandatory The URI of the file we want to import from. In templates the location parameter is usually skipped. In this case all content files (wikicontent) listed in the script as direct children of the module are searched for appropriate content. You can reduce the search with parameter id, see below.
keeprefs optional Possible values ar: yes and no. If yes all references in the imported material is recalculated and kept. If no all references are removed. no is default.
encoding optional You can spesify expected encoding. Default encoding is default (UTF-8 if not set otherwise in script).
backup optional You may spesify the catalog you want to use for backup. Default is catalog wikibck in the same catalog as the module requesting the material. You may also use the value no to suppress the backup strategy.
usecopy optional Possible values are yes and no. yes will load the backup without attempting to load the wiki-page. This will save time, but it does of course only have meaning if you have accessed and loaded the material at least once before. Default is no. This setting will be overridden by the option use-copy, see Options
id (optional) An id that match the id of the actual xmlimport in script. Has only meaning when this element has no location. One reason to use an id is processing time if you have many contentfiles to a module. Another reason may be that you have similar structures in different contentfiles and you want to be selective.

NOTE 1: WXT does not consider styles, most elements are copied "as is".

NOTE 2: WXT is not set up to collect from https (Secure connentions). If you want to access protected files, you should use normal access through a webbrowser and save the page on your disk. Then you can access the downloaded file locally.

NOTE 3: The backup strategy makes it possible to inspect and even change the downloaded content.

NOTE 4: In many cases you can achive your result by importing the wikipage by importxml and a xpath. WXT will attempt to tidy the import.

Examples:

<?_wxt importwiki 
         location="mycopiedwikifile.html" 
         dpath="/All students"?>

will extract the header on level 2, All students, and all material until the next heading at level 2, or level1.

<?_wxt importwiki  keeprefs="no" 
       location="http://en.wikipedia.org/wiki/Cougar" 
	   dpath="//Subspecies"?>

will extract a description of Subspecies (placed at header level3) in a wikipedia - page about cougars.

<?_wxt importwiki dpath="/Nature" 
     location="http://en.wikipedia.org/wiki/Halden"?>

will produce this (as of june 2009)

<div class="importwiki"><h2> Nature</h2>
<p>Halden is surrounded by forests and water so hiking and fishing
locations can easily be found. Deer and elk are a common sight, 
and wolves have also been observed
in the district along the border with Sweden. 
Raspberries, blackberries, blueberries, wild cranberries, and many 
varieties of mushroom can be found in
the woods in the early autumn. Popular destinations for hikers and
other nature lovers include Prestebakke and Kornsjø.</p>
</div>